Unical Healthchecks is perfectly suited for monitoring cron jobs. All you have to do is update your cron job command to send a HTTP request to Unical Healthchecks after a job completes.
Let's look at an example:
$ crontab -l
# m h dom mon dow command
8 6 * * * /home/user/backup.sh
The above job runs /home/user/backup.sh
every day at 6:08. The backup
script is presumably a headless, background process. Even if it works
correctly currently, it can start silently failing in future, without
anyone noticing.
You can set up Unical Healthchecks to notify you whenever the backup script does not run on time or does not complete successfully. Here are the steps to do that.
If you have not already, sign up for a free Unical Healthchecks account.
In your Unical Healthchecks account, add a new check.
Give the check a meaningful name. Good naming will become increasingly important as you add more checks to your account.
Edit the check's schedule:
8 6 * * *
in the cron expression fieldTake note of your check's unique ping URL.
Finally, edit your cron job definition and append a curl or wget call after the command:
$ crontab -e
# m h dom mon dow command
8 6 * * * /home/user/backup.sh && curl -fsS --retry 5 -o /dev/null https://healthchecks.unical.it/ping/your-uuid-here
Now, each time your cron job runs, it will send a HTTP request to the ping URL. Since Unical Healthchecks knows the schedule of your cron job, it can calculate the dates and times when the job should run. As soon as your cron job doesn't report at an expected time, Unical Healthchecks will send you a notification.
This monitoring technique takes care of various failure scenarios that could potentially go unnoticed otherwise:
The extra options in the above example tells curl to retry failed HTTP requests, and to silence output unless there is an error. Feel free to adjust the curl options to suit your needs.
/home/user/backup.sh
exits with an exit code 0.On modern GNU/Linux systems, you can look up the time zone using the
timedatectl status
command and looking for "Time zone" in its output:
$ timedatectl status
Local time: C 2020-01-23 12:35:50 EET
Universal time: C 2020-01-23 10:35:50 UTC
RTC time: C 2020-01-23 10:35:50
Time zone: Europe/Riga (EET, +0200)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no