Friday, March 5, 2010 at 3:16 am
crontab/date: timestamp in log file name
A cronjob shall run a script and write it’s output to a new logfile every day. Easy, right?
0 2 * * * echo test > test.`date +%Y-%m-%d`
This will create a file called “test.“, that will be overwritten every day …and here is why (from man crontab):
“Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.”
This works…
0 2 * * * echo test > test.`date +\%Y-\%m-\%d`

