How to detect error in cron jobs
Setup Local Mail and get cron job output mails
When a cron job starts successfully or fails to execute for some reason cron daemon automatically sends an email to the user who set the cron job. That mail contains the description of a successful job or the detailed report why the particular cron job failed.
If your local mail system is not set you will not receive those mails. The cron job output emails will just die in a local mail spool folder. So you need to set up your mailer daemon to read those mails. See this answer on How read local email in thunderbird to get all your local mails.
If your cronjob fails you will receive a mail stating the reason of failure. This is one of the best way to detect the error in setting a cron job.
Alternate ways
According to this answer one can get errors of a cronjob in a log file using redirection. But you need to set the redirection with your cron job and specify the log file by yourself.
And the /var/log/syslog
file is always there to check if your cron job is running as you expected or not.
Related videos on Youtube
sourav c.
I have been with ubuntu since Lucid (Ubuntu 9.04), part-time system administrator and web developer. I like python, C, and shell scripts. Alumni of Department of Physics, IIT Guwahati.
Updated on September 18, 2022Comments
-
sourav c. almost 2 years
The reasons why a cron job may fail is really very large. Most common reasons may be,
- Syntax error
- Using executable without proper path
- Using a shell variable which is not defined in cron environment
- Attempt to open a GUI without specifying
DISPLAY
And so on...
Sometimes it is really difficult to understand which error is preventing the job to be executed. Is there a way to detect error(s) in a cron jobs?
-
PJ Brunet over 6 yearstry
mail
and type msg # -
Melebius over 4 yearsDoes this answer your question? Why crontab scripts are not working?