| Welcome to WebmasterWorld Guest from 188.8.131.52 |
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
|Subscribe to WebmasterWorld|
|rotation + date in file name with crontab shellscript|
| 5:46 am on Sep 30, 2001 (gmt 0)|
A friend asked me this:
I need to create a command for crontab containing this:
'cp access.log xxxxxx.log' where xxxxxx represents the output from date
in any format, preferably YYMMDD or YYYYMMDD.
I will set crontab to execute this daily at 23:59:59 saving the day's
access log before it is replaced at 00:00:00
Think you could steer me the right way here?
Now, I could do this with a perl/shell combo, but how would one write a script to do this in straight shell?
| 8:45 am on Oct 2, 2001 (gmt 0)|
The 'date' command has pretty comprehensive formatting options - for the YYYYMMDD format you'd use
To use it in a shell script to set a variable, enclose it in backticks ( ` ) - ie:
cp access.log $DATE.log
| 10:25 pm on Oct 3, 2001 (gmt 0)|
SK, I knew you'd pull threw. :)
| 3:12 pm on Oct 17, 2001 (gmt 0)|
This is not an answer to the question, but it's related. I keep this line at the top of my crontab files to remind me of the syntax:
# min (0-59), hr (0-23), day of mo (1-31), mo of yr (1-12), day of wk (0-6 with 0=Sunday), command
| 5:35 am on Oct 22, 2001 (gmt 0)|
Nice little tip.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
© Webmaster World 1996-2013 all rights reserved