Script that will send an email if the cron job did not run.

Team,
Would like to know what is the best script that will send you an email if cronjob did not run.
Thanks

This question is really rather vague. But since I do not want to seesaw back and forth trying to extract details, consider:

1.cronjob opens for write a log e.g., /path/to/files/logfile
2. write a daemon in C that sleeps and wakes up every x minutes. It has a control file that tells it what files should be out there and how to check for success by finding the current file exists and reading it for error messages. It emails when it detects an error.

#1 and #2 are somewhat arbitrary because I have no idea what is needed.
How you do #1 and #2 is up to you.

Requirements:
A. There has to be a way for an independent monitor to send an alarm for a process that could never have run in the first place.

B. And for that same process to reliably write errors or the word 'failure' or something to a log file - when it does run and hits a problem. So the independent monitor can see a problem.

So it sounds like a rewrite of the cronjob script and development of a monitor.

PS: batch system software does this for you. Although cron does not necessarily do this, it can send email. But if the cronjob itself never actually is initiated then email will not work.

2 Likes

Another suggestion is to insert a line just before your cron job finishes to write out a timestamp file. Then you set up a simple second cron job to run, say, five minutes after the first job to check that the timestamp file is not more than six minutes old and, if it is, send an email saying that things aren't quite right. If the first job doesn't run at all, or crashes out before completion, then the second job will inform you of that.

2 Likes

Agree....

Thanks all