Answer

How do you monitor a cron job or a backup so a silent failure gets noticed?

By the Cloudverg engineering team · · 5 min read

Make the job call a check address when it finishes, and set a monitor to alert you if that call does not arrive on time. This is called a dead man's switch: the alert is raised by silence, so it works even when the server, the scheduler or the job itself is dead.

Why does a cron job fail without anyone knowing?

Because nothing runs when it breaks. A full disk, a changed password, an expired token, a deleted user or a server that was rebuilt without its crontab all end the same way: no output and no error. By the time you notice, the last good backup is weeks old.

How does the check work?

The monitor has two numbers. The period is how often the job should run. The grace time is how long to wait past the period before alerting. Healthchecks.io's documentation gives an example: with a one hour period and 5 minutes of grace and a last ping at 12:00, the check is late at 13:00 and down, with alerts sent, at 13:05. VergMind works the same way: if the call has not come within the period plus grace, an incident opens, and it closes by itself on the next call.

What does it look like in cron?

0 2 * * * /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 "$CHECK_URL" > /dev/null

The && matters. The call only goes out if the backup exits with success. If it fails, nothing is sent, the monitor goes late, and you get the alert. Put the real check address in an environment variable and keep it out of the script.

Should you also send a start call?

Yes. Call a start address first, then the finish address at the end. The monitor now knows the run time, and it can warn when a run goes over the longest you allow. A job that normally takes six minutes and now takes two hours is failing, even if it ends in the right place. Healthchecks.io supports this with a /start signal, and VergMind with a start address.

What else should the script check?

  • Size. Compare the output to the last one. A backup that is 3 percent of yesterday's is not a backup.
  • Exit codes in a pipe. Use set -o pipefail, or the pipe hides the failure.
  • A restore. Once a month, restore into a scratch place and open the data. The free backup and restore time tool shows whether your window and link speed even allow a full restore.
  • The schedule. The free cron explainer reads a cron line in plain words and shows its next run times, so a typo does not hide for a month.

What does it cost?

Healthchecks.io has a free plan of 20 checks, and its Business plan is $20 a month for 100 checks and includes SMS and phone credits. VergMind is $29 a month at Starter size. If cron jobs are all you need to watch, Healthchecks.io is simpler and cheaper to start. If you also want website monitors, on-call and a status page under one roof, VergMind covers them.

Quick answers

Is a ping from outside enough to monitor a cron job?

No. A ping tells you the server answers, not that the job ran. The job has to report in, and silence is what raises the alert.

What is the grace time for?

Jobs run a little late. Grace is the extra wait before the alert, so a backup that takes six minutes instead of five does not page anyone.

How do I know a backup is good and not just finished?

Check the size and run a restore test on a schedule. A job that ends with exit code 0 and an empty file passed every check but the useful one.

Sources

Add a check-in to your nightly backup

Check-in monitors are part of VergMind at $29 a month, with 14 days of every product free for a first workspace.

More guides

Smallest way to start

Get a senior architect on your problem this week

Ninety minutes a month on the cloud, AI or security question that is blocking you, a pre-read of your material and a written summary within two business days.

$450/month

Renews monthly. Cancel any time.
Prefer to pay once?

Pay $450 once for one month of the Expert architecture session. It ends on its own, nothing renews.