lweegp
September 8, 2006, 12:30am
1
Dear Gurus,
I'm trying to move a number of files from one directory to another directory with a new date stamp. This is my script:
#! /bin/csh
Today_Date=`date +%Y%M%D`
mv /usr/TRS/data/TS* /usr/TRS/backup/TS*.${Today_Date}
when i run the script i'm getting the following errors:
mv: /usr/TRS/backup/TS*.20062309/08/06 not found
Any advise?
Thanks
wee
what is the date format that u want exactly ?
date +%Y%M%D
%M - minute format
is of the format
YYYYMMMM/DD/YY
YYYYMMDD
try this,
date +%Y%m%d
lweegp
September 8, 2006, 1:48am
3
hi thanks for the help. i get the date though (see below), but getting another error message:
mv: /usr/TRS/backup/TS*.20060908 not found
any advise? thanks again.
wee
lweegp:
hi thanks for the help. i get the date though (see below), but getting another error message:
mv: /usr/TRS/backup/TS*.20060908 not found
any advise? thanks again.
wee
i think the destination should not have a '*' ... it should be a valid directory, or a filename.
lweegp
September 8, 2006, 2:39am
5
thanks. somehow it solved my problem. this is how my script looks like:
#! /bin/sh
Today_Date=`date +%Y%m%d`
mkdir /usr/TRS/backup/${Today_Date}
mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date}
so now i will create today's date as a directory and put all the files in.
the question is how do i remove those directory when they are more than 10 days old? thanks again.
you can use the find command with -mtime switch. Please do "man find" and see how it is used or you can search the forum
lweegp
September 8, 2006, 4:20am
7
This is my final script. Do u think it will work? Thanks.
#! /bin/sh
Today_Date=`date +%Y%m%d`
mkdir /usr/TRS/backup/${Today_Date}
mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date}
find /usr/TRS/backup/. -name 'T*' -mtime +1 -exec rm -f {} \;
lweegp:
This is my final script. Do u think it will work? Thanks.
#! /bin/sh
Today_Date=`date +%Y%m%d`
mkdir /usr/TRS/backup/${Today_Date}
mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date}
find /usr/TRS/backup/. -name 'T*' -mtime +1 -exec rm -f {} \;
you can try it out by running the script..
if you want to make sure, then use the shell prompt and do it step by step and you can also list the files found first, before using the actual command
listing the files more than 10 days..
find /usr/TRS/backup/. -name 'T*' -mtime +10 -ls
i thought you want to delete directories more than 10 days?
find /usr/TRS/backup/. -name 'T*' -type d -mtime +10 -ls
Then once you are sure those files listed are the ones to delete, use the actual command , eg
find /usr/TRS/backup/. -name 'T*' -type d -mtime +10 -exec .....
lweegp
September 8, 2006, 4:37am
9
ghostdog74:
you can try it out by running the script..
if you want to make sure, then use the shell prompt and do it step by step and you can also list the files found first, before using the actual command
listing the files more than 10 days..
find /usr/TRS/backup/. -name 'T*' -mtime +10 -ls
i thought you want to delete directories more than 10 days?
find /usr/TRS/backup/. -name 'T*' -type d -mtime +10 -ls
Then once you are sure those files listed are the ones to delete, use the actual command , eg
find /usr/TRS/backup/. -name 'T*' -type d -mtime +10 -exec .....
ghostdog74
many thanks to u. will try it out n let u knw the results. cheers!
lweegp
October 3, 2006, 8:36pm
11
ghostdog74:
no prob.have fun.
hi ghostdog,
tried but it seems my command is not working:
find /usr/TRS/backup/. -name 'GW*' -type d -mtime +10 -exec rm -f {} \; >> abc.log
even try to run it manually but not working at all. anything wrong with it?
thanks
wee
lweegp:
hi ghostdog,
tried but it seems my command is not working:
find /usr/TRS/backup/. -name 'GW*' -type d -mtime +10 -exec rm -f {} \; >> abc.log
even try to run it manually but not working at all. anything wrong with it?
thanks
wee
what error you encountered? at least post the error messages you have and what unexpected behaviour you seen...
lweegp
October 3, 2006, 11:02pm
13
hi ghostdog
there are no error messages. just that when i run the command nothing has take place.
i run this command
% find /usr/TRS/backup/. -name 'GW*' -type d -mtime +1 -exec rm -rf {} \;
and the following directory (in bold) should be remove but it's still there.
% ls -ltr
total 4
drwxrwxrwx 2 hulft hulft 512 Oct 2 23:02 20061002
drwxr-xr-x 2 hulft hulft 512 Oct 3 23:02 20061003
let me know if u need additional information.
thanks
lweegp:
hi ghostdog
there are no error messages. just that when i run the command nothing has take place.
i run this command
% find /usr/TRS/backup/. -name 'GW*' -type d -mtime +1 -exec rm -rf {} \;
and the following directory (in bold) should be remove but it's still there.
% ls -ltr
total 4
drwxrwxrwx 2 hulft hulft 512 Oct 2 23:02 20061002
drwxr-xr-x 2 hulft hulft 512 Oct 3 23:02 20061003
let me know if u need additional information.
thanks
the -name "GW*" -type d : means find directories with name starting
with GW. your directories are not starting with GW.
lweegp
October 3, 2006, 11:47pm
15
ohh my...thanks for pointing out....i missed out the -d...thanks thanks!