1844908 Members
1651 Online
110233 Solutions
New Discussion

date script syntax

 
SOLVED
Go to solution
Michael Windbigler
Occasional Advisor

date script syntax

I am trying to set up a script that will be run by cron to clean up date stamped log files
two days old. I can get the date to format right. ie date -u +%m%d%Y I just can't figure how to get hte system to return it two day later in the script.

Thanks
6 REPLIES 6

Re: date script syntax

Hi,

There are few datecalc utilities available to manipulate dates. I myself have written one. Use this script to find the date two days back and then delete them.

You can also get a simillar utility in

http://hpux.cs.utah.edu/

Attaching my script.

Hope this helps.
Sundar
Life is to LEARN , not to LIVE
Solution

Re: date script syntax

Attaching the man page for the script.
Life is to LEARN , not to LIVE
Devbinder Singh Marway
Valued Contributor

Re: date script syntax

A suggestion , why don't you use the find command to delete files 2 days old e.g.
find -type f -mtime +2 -exec rm -f {} ;

laters
Seek and you shall find
Devbinder Singh Marway
Valued Contributor

Re: date script syntax

A suggestion , why don't you use the find command to delete files 2 days old e.g.
find -type f -mtime +2 -exec rm -f {} ;

laters
Seek and you shall find
Rick Garland
Honored Contributor

Re: date script syntax

Watch the -u switch in the date command you have provided above. The -u switch will provide GMT. You may want date-times that are within the time zone in which you reside, in which case drop the -u switch.
Alan Riggs
Honored Contributor

Re: date script syntax

This really does seem a job for find. I would recommend limiting the search to files which match a specific pattern, unless you are certain that only the date_stamoed iles you seek are under a directory path. Something like:

find $LOG_DIR -name $LOG_FORMAT* -mtime +1 -exec rm {} \;

note: mtime +1 takes all files 2 days old or older. mtime 2 would select those files exactly two days old.