homepage Welcome to WebmasterWorld Guest from 54.166.159.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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
littleman

WebmasterWorld Senior Member littleman us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 44 posted 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?

 

sugarkane

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 44 posted 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:

#!/bin/bash
DATE=`date +%Y%m%d`
cp access.log $DATE.log

littleman

WebmasterWorld Senior Member littleman us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 44 posted 10:25 pm on Oct 3, 2001 (gmt 0)

SK, I knew you'd pull threw. :)

richcasto

10+ Year Member



 
Msg#: 44 posted 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

littleman

WebmasterWorld Senior Member littleman us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 44 posted 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