Tuesday, April 23, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 37672  / 1 Year ago, sun, january 8, 2023, 3:55:09

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?


More From » cron

 Answers
1

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.



enter image description here



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.


[#27086] Monday, January 9, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sator

Total Points: 258
Total Questions: 119
Total Answers: 101

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
;