homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

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

date +%Y%m%d

To use it in a shell script to set a variable, enclose it in backticks ( ` ) - ie:

DATE=`date +%Y%m%d`
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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved