Sending cron output to a file with a timestamp in its name

Solution 1:

Try:

0 0 * * * /some/path/to/a/file.php > $HOME/`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1

Play around with the date format, if you like; just be sure to escape any % like \%, as above.

Solution 2:

i would highly recommend that you save everything into the same file, using timestamp, as explained here.

remove

2>&1

and run it thru the timestamping script before saving it to log file (as explained in above link).


Solution 3:

You can also append your output to the log file by doing it like this:

0 0 * * * /some/path/to/a/file.php >> $HOME/cron.log 2>&1

Tags:

Cron