Where are cron errors logged?
As others have pointed out,
cronwill email you the output of any program it runs (if there is any output). So, if you don't get any output, there are basically three possibilities:
crondcould not even start a shell for running the program or sending email
crondhad troubles mailing the output, or the mail was lost.
- the program did not produce any output (including error messages)
Case 1. is very unlikely, but something should have been written in the cron logs. Cron has an own reserved syslog facility, so you should have a look into
/etc/syslog.conf(or the equivalent file in your distro) to see where messages of facility
cronare sent. Popular destinations include
In case 2., you should inspect the mailer daemon logs: messages from the Cron daemon usually appear as from
[email protected]. You can use a
MAILTO=...line in the crontab file to have cron send email to a specific address, which should make it easier to grep the mailer daemon logs. For instance:
[email protected] 00 15 * * * echo "Just testing if crond sends email"
In case 3., you can test if the program was actually run by appending another command whose effect you can easily check: for instance,
00 15 * * * /a/command; touch /tmp/a_command_has_run
so you can check if
crondhas actually run something by looking at the mtime of
Do these "emails" go in a file also? I'm using shared web hosting and don't think they'd know where to email me.
I appreciate the advice in case 3 to check if the command is even running. In my case, cron wasn't running my job because I had recently changed the server's timezone and needed to restart the cron server so it would evaluate the cron times in the proper timezone.
You can always explicitly send the job output to a log file:
0 8 * * * /usr/local/bin/myjob > /var/log/myjob.log 2>&1
Keep in mind that this will supercede the mail behaviour that has been mentioned before, because crond iself won't receive any output from the job. If you want to keep that behaviour you should look into tee(1).
Sure! Any kind of I/O redirection will do, even `| /usr/bin/logger` if you wish, as cleverly suggested by Stefan. Pick your poison: https://www.tldp.org/LDP/abs/html/io-redirection.html
If you aren't seeing the mails, you might be spamming [email protected] with the errors which can be quite annoying to the people who use that account for monitoring. Try sending the output to Syslog instead:
*/5 * * * * yourcronjob 2>&1 | /usr/bin/logger -t yourtag
Then, wait for the cronjob to run and look for the error in /var/log/messages (or /var/log/user.log on some systems).
This works great for errors messages which are only 1-2 lines long, such as "yourcronjob: command not found". It also makes use of your existing syslog infrastructure (Logrotation, central syslogging, Splunk, etc.) It also reduces email spam to root.
It may not be a good solution if your cronjob generates hundreds of lines of output.
You should get email from
crondwhen the job either fails to run or when the job returns a nonzero exit code. Try typing:
at the command prompt.
mailx(1)is the basic mail reading program on most every Unixlike system. It is very primitive by modern standards, but you can pretty much count on it to always be available. Other, better mail agents may be available, but there are enough of them that you never know which one is installed on some random machine you happen to be using.
Note that unless you have configured your system as an Internet email server, this mail subsystem is used only within the machine. You can send email to and receive from other users on the machine, but you may not be able to send email out to the world, and email from the outer world certainly won't be able to come to your machine.
The default cron configuration will send you a mail with the output of your program. If this fails, you could try wrapping your failing program in a shell script that ensures that the program does not fail, and you could further log the output.
This is a configurable setting on some cron implementations.
Cron logs basic info to
/var/log/messages, but mails any program output to the invoking user.
I stumbled across this thread a few years ago experiencing the same problems and just recently came across a solution to the above mentioned cases by Ricardo. The lack of an email is hard to detect (as you mentioned) and you certainly don't want to spam your [email protected] email. If interested check out deadmanssnitch.com.. This tool seems to solve the aforementioned cases. Seems pretty simple to use— just add the bit of code the tool gives you to your cronjob. If your job fails to run at a specified internal, you will be alerted. If you job starts running again you'll also be alerted.
vixie-cron, so I don't know if this applies to everything. But I have a
dead.letterfile that contains all the output of the job.
/root/folder I have
crons.cronwhich I set as my crontab by running
dead.letterwill be created in
Edit I just Google'd
dead.letter, and it's an undeliverable mail. It has nothing to do with cron apparently. If you don't have mail set up correctly (like me), you'll have the file.
Another useful trick is to see what scripts are actually executed.
This is done with
run-parts -v --test /etc/cron.hourly/
If your script does not show up it will not be executed.
This btw only works for the scripts installed in the
/etc/cron.hourlydirectory. It does not show you items that are set in your
For newbies, this could be a pain to debug. Be sure not to interchange the minute and the hour values. The minute comes first, then the hour. When you supply values less than 12 for each, it will accept them but may not work as expected or at all.