How to monitor cron jobs
Monitor cron jobs with a heartbeat, also called a dead man's switch: each run pings a unique URL when it finishes, and you are alerted when a ping does not arrive on schedule. Report the exit code and a start ping too, so failures and hung runs alert as well. Cron itself never tells you a job stopped.
What can go wrong with cron jobs
- It silently stops. The server was rebuilt, the crontab was edited, cron is not running, or the disk is full. A job that does not run produces no error anywhere.
- Works in a shell, fails in cron. Cron runs with a minimal environment (
PATH=/usr/bin:/bin, no profile). Commands that rely on your shell's PATH or variables fail only under cron. - The % sign. In a crontab line,
%means newline;date +%Fmust be writtendate +\%For the command is cut off. - Overlapping or hung runs. A run that takes longer than the interval stacks up on the next one; a hung run blocks forever.
flock -nprevents overlap but not hangs. - Errors mailed to nobody. Cron mails output to the crontab owner; on most servers that mail goes nowhere.
The signals that matter, with alert thresholds
| Signal | Alert when | Why it matters |
|---|---|---|
| Success ping | late by more than the grace period | The job did not finish successfully. |
| Exit code | non-zero | It ran and failed. |
| Run duration | over a maximum run time | Hung or much slower than usual. |
| Output of failed runs | kept with the ping | Why it failed, without SSH. |
| Value sent with the ping (<code>?value=</code>) | below a minimum or above a maximum | It ran but did nothing, or found problems. |
Thresholds are starting points. Tune them after a week of data: an alert nobody acts on should be raised or removed.
How to check cron jobs by hand
crontab -l sudo crontab -l -u root ls /etc/cron.d/
systemctl status cron
grep CRON /var/log/syslog | tail -20 # or: journalctl -u cron --since today
env -i SHELL=/bin/sh PATH=/usr/bin:/bin HOME=$HOME /bin/sh -c '/usr/local/bin/my-job.sh'
Healthchecks-compatible: change hc-ping.com to puzaricloud.in/ping
Vigil's heartbeat URLs follow the same grammar as Healthchecks.io's ping API, so a script, backup tool or container that already pings https://hc-ping.com/<uuid> works with Vigil when you swap the base URL and use your Vigil heartbeat's token. New heartbeats get a UUID token, so tools that insist on a UUID accept it. (Vigil is an independent product with a compatible URL format; it is not affiliated with Healthchecks.io.) Comparing options? See Healthchecks.io alternatives, side by side on ping-URL compatibility.
| Healthchecks URL | Vigil URL | Meaning |
|---|---|---|
| https://hc-ping.com/<uuid> | https://puzaricloud.in/ping/<uuid> | success |
| …/<uuid>/start | https://puzaricloud.in/ping/<uuid>/start | run started (duration tracking) |
| …/<uuid>/fail | https://puzaricloud.in/ping/<uuid>/fail | failure: alert now |
| …/<uuid>/<0-255> | https://puzaricloud.in/ping/<uuid>/$? | exit status: 0 success, 1-255 failure |
| …/<uuid>/log | https://puzaricloud.in/ping/<uuid>/log | store a message, no state change |
| ?rid=<uuid> | ?rid=<uuid> | pair a finish with its own start when runs overlap |
GET, HEAD and POST all work. A POST body up to 100 KB is kept as the run's log and shown on the monitor; the response header Ping-Body-Limit says how much is kept. Not supported: slug URLs (/<ping-key>/<slug>) and auto-creating checks with ?create=1; create the heartbeat in Vigil first and copy its URL.
- borgmatic: set
healthchecks:→ping_url: https://puzaricloud.in/ping/<uuid>(top level since borgmatic 1.8.0; underhooks:before that). borgmatic then pings when a backup starts, finishes or fails, and attaches its logs to the ping. - runitor:
runitor -api-url https://puzaricloud.in/ping -uuid <uuid> -- ./backup.shwraps a command and reports start, exit status and output. - Shell scripts and containers that read a
HEALTHCHECKS_URL-style variable: set it to your Vigil ping URL.
Alert when a job ran but did nothing: ?value=
A job can exit 0 and still let you down: the import found 0 rows, the mailer sent 0 emails, or the nightly reconciliation found 7 mismatches. Add the number to the success ping as ?value= (?count= works too) and give the heartbeat a range under Alert if value is below and Alert if value is above. A value outside the range alerts and opens an incident, the same as a failure ping. The next value inside the range closes it. A ping without a value is a normal success, so jobs that do not send one keep working.
ROWS=$(/usr/local/bin/import.sh) && curl -fsS -m 10 "https://puzaricloud.in/ping/<token>?value=${ROWS:-0}"MISMATCHES=$(/usr/local/bin/reconcile.sh); curl -fsS -m 10 "https://puzaricloud.in/ping/<token>?value=$MISMATCHES"
Values can be whole numbers or decimals, like 42 or 3.5. Anything else gets HTTP 400, and curl -f then fails in the job's own log. An empty value counts as no value, so write ${ROWS:-0} when an empty variable should alert. The last values and the range are shown on the monitor's Checks tab. For a full example with payments, see monitoring Stripe webhooks.
See it in 16 seconds
What the clip shows
- New heartbeat: name "Nightly DB backup", expected every 1,440 minutes with a 30-minute grace period.
- Saved: the page shows the success, start and failure ping URLs (Healthchecks-compatible).
- Copy-paste examples for crontab, GitHub Actions and Python.
- The job pings the URL and the monitor turns from pending to up.
How to watch cron jobs with Vigil
- In New monitor create a Heartbeat. Choose cron schedule, paste the expression and the server's timezone (e.g.
0 2 * * *in Asia/Kolkata), and a grace period longer than a normal run. - Append the ping:
0 2 * * * /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 https://puzaricloud.in/ping/<token>. With&&only successful runs ping. - Better: report every outcome.
/usr/local/bin/job.sh; curl -fsS -m 10 https://puzaricloud.in/ping/<token>/$?sends the exit code (0 = success, anything else = failure alert at once, not at the end of the grace period). - Track duration: ping
https://puzaricloud.in/ping/<token>/startbefore the job and set a maximum run time; a run that started but never finished alerts. - Keep the output:
job.sh > /tmp/job.log 2>&1; curl -fsS -m 10 --data-binary @/tmp/job.log https://puzaricloud.in/ping/<token>/$?. The body is stored with the ping and shown on the monitor. - Catch runs that did nothing: send a number with
https://puzaricloud.in/ping/<token>?value=$ROWSand set Alert if value is below or above on the heartbeat (see value rules).
Every alert goes to the channels you pick: email, Slack, Telegram, Discord, Microsoft Teams, Pushover, webhooks or on-call paging. Failures are confirmed by a second check before anyone is woken up.
cron jobs monitoring FAQ
What is a dead man's switch?
A check that fires when something stops happening. The job keeps "pressing the switch" by pinging; if the pings stop, the monitor alerts. It is the only way to notice a job that no longer runs at all.
What should the grace period be?
Long enough for a normal run plus a little delay, short enough that you hear about it in time. Our cron explainer suggests one for any expression, and each schedule page lists one.
What if the server cannot reach the internet?
The ping needs outbound HTTPS to puzaricloud.in. If that fails, the heartbeat goes late and alerts, which is the safe direction. Use --retry so a single network blip does not cause a false alarm.
Can one heartbeat watch several servers running the same job?
Use one heartbeat per server, so you know which one stopped; tags group them on the dashboard.