How to enable logging for cron on Linux
If you’re looking to troubleshoot cron jobs, the best way might be to enable logging. Jack Wallen shows you how.
Cron is a time-based job scheduler in Linux that runs system jobs and allows users to create jobs that are executed on a regular basis. Cron does simple things like regularly emptying the /tmp folder, cleaning PHP sessions, running backups, and so much more.
But the one problem with cron is that, out of the box, it doesn’t have a dedicated log. This can be a problem when you’re creating your own cron jobs and you need to debug them.
Without a log, you might never know if that job ran. This happened to me recently, when I created two cronjobs to keep Google Drive in sync with a local directory with rclone. I had no idea if the jobs were running, without comparing the folders. Fortunately, it’s possible to enable logging with cron.
Let’s find out how.
Open a terminal window on the Linux machine that houses the cron job and issue the command:
sudo nano /etc/rsyslog.d/50-default.conf
In that file, look for the line that starts with #cron.*.
Remove the # symbol and then in the second column add:
/var/log/cron.log
Save and close the file.
Next, restart syslog with the command:
sudo systemctl restart rsyslog
At this point, you should now see the new log file /var/log/cron.log. If you don’t see it immediately, it’ll appear the next time a cron job runs.
You can then read through that file with the command less /var/log/cron.log and troubleshoot any cronjobs that may or may not be running.
Also see
Image: Jack Wallen