Text
So recently I ran into an issue where our backup script would only work properly when we ran it manually. That’s another story. However to try and catch what was wrong with the cron job we had to figure out a way to log what was happening. So what I did was the following on a CentOS machine. I opened the crontab file /etc/crontab and inside there you have four jobs that run at different times:
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
I was running the script under cron.daily so that’s what I wanted to log to see what was happening. So I appended this:
> /home/admin/s3sync/backup.log
so you get:
02 4 * * * root run-parts /etc/cron.daily > /var/log/backup.log
Which will output the results of your cron job to a backup.log text file. The single > will overwrite the log file with every run, which is what I want. If it does it’s job right, there is no reason to hold on to those old logs. Plus I know when it doesn’t work so then I can just check the log for that day. However if you did want the collect the output for each day, you can append the output to the log file by using two » instead of one >. If you do that, I would highly recommend adding that log file to the log rotation script.
I hope this helps anyone is a similar position!