Debugging crontab jobs

naiquevin picture naiquevin · Feb 3, 2011 · Viewed 76k times · Source

I have added a crontab entry on a Linux server that will run a Java executable. The Java code uses its own class for logging errors and messages into a log file.

But when I checked the log file after the scheduled time, no messages were logged. There should have been at least one log message saying the execution had started.

So there are two possible causes:

  1. The code executed but didn't log;
  2. Or, the code didn't execute at all.

The log file specified has chmod 777 permissions so I'm guessing it's the second cause here.

Why wouldn't a crontab job execute at its scheduled time? And how do I debug this without any kind of logging happening?

I have read that if there is an error cron sends an email to the user. How do I find out which email address is associated with the user?

Answer

Mehdi Yedes picture Mehdi Yedes · Jan 19, 2016

You can enable logging for cron jobs in order to track problems. You need to edit the /etc/rsyslog.conf or /etc/rsyslog.d/50-default.conf (on Ubuntu) file and make sure you have the following line uncommented or add it if it is missing:

cron.*                         /var/log/cron.log

Then restart rsyslog and cron:

sudo service rsyslog restart
sudo service cron restart

Cron jobs will log to /var/log/cron.log.