How to enable logging for cron on Linux

If you’re hunting to troubleshoot cron work, the finest way could possibly be to enable logging. Jack Wallen displays you how.

Cron is a time-based mostly career scheduler in Linux that operates method jobs and makes it possible for end users to make work that are executed on a common basis. Cron does basic matters like often emptying the /tmp folder, cleaning PHP periods, working backups, and so a great deal more. 

But the just one problem with cron is that, out of the box, it does not have a devoted log. This can be a difficulty when you might be producing your personal cron employment and you require to debug them. 

Without having a log, you could hardly ever know if that position ran. This took place to me recently, when I produced two cronjobs to maintain Google Drive in sync with a local directory with rclone. I experienced no thought if the work opportunities ended up functioning, without the need of comparing the folders. The good news is, it really is probable to enable logging with cron. 

Let us come across out how. 

Open up a terminal window on the Linux device that residences the cron job and issue the command: 

sudo nano /and so forth/rsyslog.d/50-default.conf

In that file, search for the line that starts off with #cron.*. 

Clear away the # symbol and then in the next column add:


Help save and close the file. 

Upcoming, restart syslog with the command:

 sudo systemctl restart rsyslog

At this level, you must now see the new log file /var/log/cron.log. If you really don’t see it straight away, it’s going to show up the upcoming time a cron work runs. 

You can then read via that file with the command less /var/log/cron.log and troubleshoot any cronjobs that could or may not be functioning. 

Also see


Image: Jack Wallen

Source website link

You may also like