Check if cron is working with monit

I encountered a problem last week with cron. crond was running but the jobs seems to not work. After debugging the crontab, I saw that on one job, the username was missing.

Nothing was written in the logs to say that there was a problem.

To avoid future problems, I wrote an alert for monit.

In my crontab, I’ve added the following job:

*/5 * * * *       root    touch /tmp/check_cron

This job will update the timestamp of the file /tmp/check_cron every 5 minutes.

And in monit configuration (/etc/monit/monitrc), I’ve added the following alert:

check file check_cron with path /tmp/check_cron
        if timestamp > 10 minutes then alert

If the crontab is not working, monit will send you an alert email like this:

Subject: monit alert --  Exists check_cron

Exists Service check_cron 

	Date:        Thu, 27 Nov 2008 21:21:53 +0100
	Action:      alert
	Host:        myhost
	Description: 'check_cron' file exist

Your faithful employee,