Sending cron output to a file with a timestamp in its name
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.
I would highly recommend that you save everything into the same file, using timestamp, as explained on Abdullah Diab’s Blog.
remove
2>&1
... and run it through the timestamping script before saving it to log file.
timestamp.sh
script:
#!/bin/bash
while read x; do
echo -n `date +%d/%m/%Y\ %H:%M:%S`;
echo -n " ";
echo $x;
done
Remember to chmod +x timestamp.sh
to make it executable.
Then edit the cron job line using crontab -e
to be like this:
/path/to/my/command.sh 2>&1 | /path/to/timestap.sh >> /var/log/cron/my_log.log