Operating System - HP-UX
1833514 Members
3359 Online
110061 Solutions
New Discussion

Need to append previous day's date to a filename

 
SOLVED
Go to solution
Robert Fisher_1
Frequent Advisor

Need to append previous day's date to a filename

Hello,

I am trying to append a date suffix to a log filename so that I can start a new log. I would like the format to be .yyyy_mm_dd. Now for the hard part. The script runs Monday through Friday. On Mondays, I would like to use the previous Friday's date and on the other weekdays the previous day's date. Trying to get this thing to work is driving me crazy. Please help.

Thanks, Bob
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Need to append previous day's date to a filename

Hi Bob:

I can get you going in a couple of lines of code. How about this:

FILENAME="xxxx" # your filename
LOGNAME="${FILENAME}.$(caljd.sh -y -S '_' $(caljd.sh -p 1 -x 0 -x 6))"

Believe it or not, you are done. The inner caljd.sh says skip to the previous day (-p 1); if that falls on a Sunday (-x 0) or Saturday (-x 7) keep going backwards. The outer caljs.sh says take the argment and return a calendar date in yyyy mm dd (-y) order and use '_' (-S '_') as a separator.

Caljd.sh is my date hammer; now where's your date nail?

Regards, Clay




If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Need to append previous day's date to a filename

Ooops, the code is right but the explanation is wrong. -x 6 skips Saturdays. Sorry about that.

If it ain't broke, I can fix that.
Robert Fisher_1
Frequent Advisor

Re: Need to append previous day's date to a filename

Wow! Perfect!!!

Clay, the funny thing is that I already had a copy of your caljd.sh script. You used it in an Omniback copy script. I just didn't know what it did. I just looked at it again and I have no idea how it works but it works!!

Thanks, Bob