Click to See Complete Forum and Search --> : date question


rdeschene2
05-30-2005, 08:54 PM
I have a little bash shell script which is used to backup files (via cron) to an NASLite server every 7 days.

a=$(date +%b_%d_%Y)
tar -lcpf /tmp/laptopbackup.$a.tar /home
ncftpput 192.168.0.5 /Disk-1/laptop /tmp/laptopbackup.$a.tar

The filename thus includes the date on which it is made, which is very handy for the novice. e.g. laptopbackup.May_29_2005.tar

I would like to keep on the NAS only the last 4 weeks of tar archives.

As the filenames include the date, I could do this by having the script delete (via ncftp) all files that were made 5 weeks ago. So if the shell script was running on May 29/2005, this would delete the file named:
laptopbackup.Apr_24_2005

How can I set a variable so that it's value is the date (5 weeks * 7 days/week = ) 35 days ago ? That would do the trick as I could then use
ncftp -rm laptopbackup.($variable for date 35 days ago).tar
to delete these older files ?


Thank you,
Rick D.

rdeschene2
06-01-2005, 07:57 PM
I appear to have found basically what I was looking for here. It was more a matter of format and accepted dialogue than anything.

http://www.unix.com/showthread.php?s=&threadid=7919

Using either:

b=$(date --date="5 weeks ago" +%d_%b_%Y)

OR

b=$(date --date="35 days ago" +%d_%b_%Y)

gives me the $b variable value (Apr_24_2005 in the preceding example) I wanted.


Rick D.