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_FILE.winframe.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
lphillips120898Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ahoffmannConnect With a Mentor Commented:
if there is no perl, 2 other possibilities, but both need to beat some dragons (1-Jan, 1-Mar, etc.), depending on your OS:
   1. old_file=`date -v -2d +%y%m%d`
   2. old_file='env TZ=GMT+48 date +%y%m%d`
(keep above questions in mind too)
0
 
ozoCommented:
Does your system recognize 48 hour time zone offsets?
Do you have Perl on your system?
Could you just delete all *.file.txt files that are two days old?
0
 
lphillips120898Author Commented:
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
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
ahoffmannCommented:
keep the beasty dates in mind: 1-Jan, 1-Mar, etc.
Some UNIX won't do it the way you expect
0
 
lphillips120898Author Commented:
I don't understand.  What happens with those dates?  Not that it's a big deal, just curious.
0
 
ahoffmannCommented:
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)
0
All Courses

From novice to tech pro — start learning today.