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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
ahoffmannCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.