lphillips120898
asked on
System Date Variable Minus 2 Days
I've setup cron jobs to kick off certain processes and write logs generated by those processes. The log uses a data variable in the name so the log files have the date incorporated into the name of the file (i.e. 120299.file.txt).
The way the date is appended to the file is by setting a variable - see the following:
LOG_FILE=`date +%y%m%d`
export LOG_FILE
savegrp -c winframe NT > /home/scripts/logs/$LOG_FI LE.winfram e.NT.log 2>&1
I now have the need to set up a cron job, which will delete all the log files preceded by the date from two days before the current date. Is it possible to set a variable, which is equal to the system date minus two days? I would then use "rm" to remove all the files preceded by that variable.
Thanks,
Lisa
The way the date is appended to the file is by setting a variable - see the following:
LOG_FILE=`date +%y%m%d`
export LOG_FILE
savegrp -c winframe NT > /home/scripts/logs/$LOG_FI
I now have the need to set up a cron job, which will delete all the log files preceded by the date from two days before the current date. Is it possible to set a variable, which is equal to the system date minus two days? I would then use "rm" to remove all the files preceded by that variable.
Thanks,
Lisa
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I prefer not to just delete the files that are two days old, I want to specify to delete files with a certain date prefixing the file name - i.e.
rm 121099*.txt
I tried both options above. Number 1 didn't like the "-v" paramater. Number 2 worked like a charm!
Thanks!
Lisa
rm 121099*.txt
I tried both options above. Number 1 didn't like the "-v" paramater. Number 2 worked like a charm!
Thanks!
Lisa
keep the beasty dates in mind: 1-Jan, 1-Mar, etc.
Some UNIX won't do it the way you expect
Some UNIX won't do it the way you expect
ASKER
I don't understand. What happens with those dates? Not that it's a big deal, just curious.
going back a day or 2, is not trivial
some OSs cannot go back over new years eve, which results in very strange dates, it also may cause trouble if the previous day is another month.
If following returns 31.Dec you can be happy:
sh -c "TZ=GMT-380; export TZ; env TZ=GMT+48 date"
(please adjust values to your timezone)
some OSs cannot go back over new years eve, which results in very strange dates, it also may cause trouble if the previous day is another month.
If following returns 31.Dec you can be happy:
sh -c "TZ=GMT-380; export TZ; env TZ=GMT+48 date"
(please adjust values to your timezone)
Do you have Perl on your system?
Could you just delete all *.file.txt files that are two days old?