Thursday, November 3, 2011

Crontab entry to generate an output file with 'date' format...


No time to blog too much on this.

Here is the simple change that I wanted from crontab.

Instead of writing the log into one file (appending) every time the crontab is initiated (and you know how big the file is going to be after few days/weeks/months) I decided to write into its own file with the Date and Time attached to the file name.

Original crontab entry with a file being appended with the results:

00 15 * * 1-6 /home/san/test.sh >> /home/san/test.log

So, changed to below to have the date and time part appended to the file name instead:

00 15 * * 1-6 /home/san/test.sh > /home/san/test.crontab.log.`date +%d.%m.%y.%R`

Damn thing wont work... No file is generated...

what the hell... that part of the date portion is correct and sure thing works fine in shell script...

Well, found that % is also treated as "comment" in crontab so gottaa escape that character with backslash to make it work.

Here is the correct entry:

00 15 * * 1-6 /home/san/test.sh > /home/san/test.crontab.log.`date +\%d.\%m.\%y.\%R`

Now, there is a file that gets created with the date format that I wanted...

No comments:

Post a Comment