Monitor a cron job and get a WhatsApp alert when it stops
A cron job that stops running looks exactly like one that ran successfully: silence. There is no error, no log line, no failed request. You find out when you need the thing it was producing — usually a backup, usually at the worst moment.
The fix is a dead-man's switch. Your job tells a service it finished; if that message does not arrive on time, the service tells you.
Add to the end of your cron line
# Runs your job, then reports success only if it exited 0
0 3 * * * /usr/local/bin/backup.sh && curl -fsS -m 10 https://hb.alertkite.com/p/YOUR_TOKENSetting it up
- Create a heartbeat monitor in AlertKite and copy its ping URL.
- Append the curl to your cron line, after your command and joined with &&.
- Set the expected period to match your schedule — hourly, daily, whatever it is.
- Wait for the first run. The monitor turns green the moment it checks in.
Why && and not ;
With && the ping only happens if your command succeeded. With ; it pings regardless, which means a job that fails every night still reports itself healthy — worse than no monitoring, because now you trust it.
Reporting failures explicitly
Append /fail to the same URL to say the job ran and went wrong: `|| curl -fsS https://hb.alertkite.com/p/YOUR_TOKEN/fail`. Combined with the success ping, you can distinguish 'did not run' from 'ran and broke', which are very different problems.
Measuring how long it took
Call /start at the beginning and the plain URL at the end, and the run duration is recorded. Useful for spotting a backup that still succeeds but has quietly gone from four minutes to forty.
The -m 10 matters
It caps curl at ten seconds. Without it, an unreachable monitoring service can hang your cron job indefinitely — the monitoring becoming the outage is a real and embarrassing failure mode.