2011-10-17

Save cron output to file with a timestamp in its filename

It's simple but you have to escape all % in date's parameter.

Run "crontab -e" to edit your cron jobs.

# do not forget to escape % to \% in date's parameter
* * * * * /usr/bin/php /path/script.php > /var/log/output-`date +\%Y\%m\%d\%H\%M`.log 2>&1

This will create "output-201110170929.log" in /var/log. If you want to change the filename format, see "man date".

No comments:

Post a Comment