How to monitor cron jobs and get alerted when one fails or doesn't run
On this page
- The four ways a cron job breaks quietly
- What MAILTO and || curl miss
- Step 1: Create a monitor with the same schedule
- Step 2: Add one line to the crontab
- Step 3: Catch jobs that hang
- Step 4: Pick the grace period and the stuck-after time
- Test it before you trust it
- Crontab gotchas that break the ping itself
- FAQ
- Start with the job you'd least like to find broken
To get alerted when a cron job fails or doesn't run, add one curl call after the job that reports its exit code to a heartbeat URL: job; curl -fsS -m 10 --retry 3 https://stallbell.com/p/TOKEN/$?. A non-zero code raises a Failed run alert at once, and if no ping arrives by the scheduled time plus a grace period, you get a Missed run alert instead. Add a start ping as well and you also hear about jobs that hang.
Cron doesn't tell you when a job fails. It runs the command, mails any output to a mailbox nobody reads, and moves on. And if the job never starts at all, because the server rebooted, the crontab was overwritten, or the script was renamed, cron has nothing to say.
This guide sets up an alert for both cases with one line of curl, then shows a small wrapper that also catches jobs that hang. You need shell access to the machine that runs the crontab and a free Stallbell account. It takes about five minutes per job.
The four ways a cron job breaks quietly
| What goes wrong | What cron does | What catches it |
|---|---|---|
| The job exits with an error | Mails the output to MAILTO (often nobody) | Report the exit code: Stallbell alerts on a failure |
| The job never starts (cron stopped, line deleted, server down) | Nothing | A missed-run alert: no ping by the expected time plus a grace period |
| The job hangs (a lock, a dead network call) | Nothing, until the next run piles up behind it | A start ping, then a stuck-run alert if no finish arrives in time |
| The job exits 0 but did nothing (an empty export, a blank AI answer) | Nothing | Send the job's output and let Stallbell flag an empty result |
The first one is the only case cron can tell you about. The rest are silent, and they're the ones that hurt: you find out days later from a customer, a missing backup or an empty report.
What MAILTO and || curl miss
The classic fixes each catch one row of that table.
MAILTO=you@example.comemails you whatever the job prints. It only helps if the job prints something when it fails, the server can send mail, and you read it. It also emails you on success if the job is chatty.chronicfrom the moreutils package helps here: it runs a command and prints its output only when the command fails, so cron only mails you about failures.job || curl https://hooks.example.com/alertcalls a webhook when the job fails. It's better than mail, but it can't fire if the job never runs, and it can't tell a hung job from a slow one.
Both are push-on-failure. Neither notices silence. For that, the job has to check in every time it runs, and something outside the server has to notice when the check-ins stop. That's what a heartbeat monitor does.
Step 1: Create a monitor with the same schedule
- Sign in to Stallbell with your email. You land on a screen with a ready-made monitor called
my-first-job, its ping URL and a copy button. Rename it after your job, for examplenightly-backup. - Set the schedule to match the crontab line. The start screen lets you change the name and a fixed interval (Every) only, so open the monitor (Monitors in the top bar, then
nightly-backup). Under Thresholds, set How it runs to On a cron schedule, enter the same five fields in Cron expression (for example0 3 * * *), and set Schedule timezone to the timezone your server's cron uses. Then press Save alert settings. With an expression, Stallbell expects a check-in shortly after each scheduled time. With a period (for example "1 day"), it expects one a day after the last check-in, so the deadline drifts with how long the job ran. - Leave Grace period at 5 minutes for now. Step 4 covers how to choose it.
- Copy the ping URL. It looks like this:
https://stallbell.com/p/TOKEN
The token in the URL is the only credential. Anyone with the URL can check in for that monitor, so keep it out of public repos. You can rotate it from the monitor page.
Stallbell starts watching for missed runs after the first check-in arrives, so a new monitor won't alert before you've wired it up.
Step 2: Add one line to the crontab
Stallbell's ping URL takes the exit code at the end: /0 means success, and any other number from 1 to 255 means the run failed. The shell already has the job's exit code in $?, so one line reports both outcomes:
curl -fsS -m 10 --retry 3 https://stallbell.com/p/TOKEN/$?
Put it straight after the job, on the same crontab line, separated by ;:
0 3 * * * /usr/local/bin/backup.sh; curl -fsS -m 10 --retry 3 https://stallbell.com/p/TOKEN/$? > /dev/null
What each part does:
| Part | Why |
|---|---|
; | Runs curl whether the job succeeded or failed. (&& would skip the ping on failure. More on that below.) |
$? | The exit code of the command just before it: 0 on success, the job's own code on failure |
-f | Makes curl exit non-zero if Stallbell answers with an error (for example 404 for a wrong token), so the problem shows up in cron's mail instead of passing silently |
-sS | No progress bar, but still print errors |
-m 10 | Give up after 10 seconds, so a network problem can't hang your cron slot |
--retry 3 | Retry a few times on a timeout or a temporary server error |
> /dev/null | Stallbell replies with a short JSON line. This keeps it out of cron's mail |
That's the whole integration. When the job exits non-zero, Stallbell opens a Failed run incident and emails you. New monitors alert on the first failure. You can raise Failures in a row in the monitor settings if a job is allowed to fail once in a while. When the next run succeeds, you get a recovery email.
If no ping arrives by the next expected time plus the grace period, you get a Missed run email instead. That covers the job that never started.
Step 3: Catch jobs that hang
The one-liner only reports when the job ends. If the job hangs, there's no end, so you'd only hear about it from the missed-run alert on the next schedule, which for a nightly job is a day later.
To catch a hang, send a ping when the job starts too. Then Stallbell knows a run is in progress, and opens a Stuck run incident if no finish arrives within the monitor's Stuck after time (1 hour by default).
Here's a small wrapper script that does it. Save it as /usr/local/bin/stallbell-run and make it executable (chmod +x):
#!/bin/sh # stallbell-run: tell Stallbell when a command starts and how it ended. # Usage: stallbell-run PING_URL command [args...] url="$1"; shift run_id="$(date +%s)-$$" curl -fsS -m 10 --retry 3 -o /dev/null "$url/start?run_id=$run_id" started=$(date +%s) "$@" code=$? duration_ms=$(( ($(date +%s) - started) * 1000 )) curl -fsS -m 10 --retry 3 -o /dev/null "$url/$code?run_id=$run_id&duration_ms=$duration_ms" exit "$code"
Then wrap the job in the crontab:
0 3 * * * /usr/local/bin/stallbell-run https://stallbell.com/p/TOKEN /usr/local/bin/backup.sh
What it does:
- Sends
/startwith arun_id, so the start and the finish join into one run in Stallbell. - Runs your command exactly as before, with the same output and the same exit code (so cron's own mail still works).
- Sends the exit code to the ping URL with the same
run_idand how long the run took (duration_ms). - Never blocks the job on Stallbell: if a ping fails, curl prints an error and the job still runs.
If a job should never run longer than a set time, put timeout in front of it as well. A job killed by timeout exits with code 124, which reaches Stallbell as a failure:
0 3 * * * /usr/local/bin/stallbell-run https://stallbell.com/p/TOKEN timeout 2h /usr/local/bin/backup.sh
Is your job a Python script?
You can report from inside the script instead of the crontab. This uses only the standard library and won't let a monitoring problem crash your job:
import urllib.request
PING = "https://stallbell.com/p/TOKEN"
def ping(path=""):
try:
urllib.request.urlopen(PING + path, timeout=10).read()
except Exception as exc: # never let monitoring break the job
print(f"Stallbell ping failed: {exc}")
def main():
... # your job
ping("/start")
try:
main()
except Exception:
ping("/fail")
raise
ping()A bare ping (no path) counts as success. If main() raises, the script reports /fail and then re-raises, so the traceback still reaches cron's mail and the exit code is still non-zero.
Step 4: Pick the grace period and the stuck-after time
Two settings decide when you hear about a problem:
- Grace period (default 5 minutes; anything from 1 minute to 1 day, entered as a number and a unit): how long after the expected time Stallbell waits before calling a run missed. Make it a bit longer than the job's usual start delay, and longer than its run time if you only send the finish ping.
- Stuck after (default 1 hour; 1 minute to 1 day): how long a run can go between
/startand its finish (or its last progress ping) before it's called stuck. Set it comfortably above the slowest normal run.
Starting points:
| Job | Crontab | Pings | Grace period | Stuck after |
|---|---|---|---|---|
| Health task every 5 minutes, runs in seconds | */5 * * * * | one-liner | 2 minutes | not used |
| Hourly sync, 2 to 5 minutes | 0 * * * * | wrapper | 5 minutes (default) | 15 minutes |
| Nightly backup, 20 to 40 minutes | 0 3 * * * | wrapper | 10 minutes | 90 minutes |
| Weekly report, up to 3 hours | 0 6 * * 1 | wrapper | 15 minutes | 4 hours |
If you send only the finish ping, the grace period has to cover the whole run. A nightly job that takes 40 minutes needs more than 40 minutes of grace, or every run will look late. That's another reason to use the wrapper for anything slow: the start ping arrives on time and the finish can take as long as Stuck after allows.
Test it before you trust it
- Failure: run the wrapper by hand with a command that fails:
bash /usr/local/bin/stallbell-run https://stallbell.com/p/TOKEN sh -c 'exit 3'You should get a Failed run email. It shows the run ID,In a row: 1andExit code: 3, with a link to the monitor. On the monitor page, Recent runs lists the run asFailedwith its start time. Click it to open the Run drawer: it shows the status, when the run started and finished, its duration,exit 3, and any message you sent. Incidents shows the open Failed run.
- Recovery: run it again with
trueinstead. You should get a Recovered email (for example "🟢 Recovered: nightly-backup (My project), down 1 min"), and the incident is marked resolved. - Missed run: comment out the crontab line (
crontab -e, add#) and wait past the next scheduled time plus grace. You should get a Missed run email. Uncomment the line afterwards; the next check-in closes the incident. - Stuck run (optional): set Stuck after to 1 minute and run the wrapper with
sleep 180. A Stuck run email should arrive within a minute or two after the first 60 seconds. Put the setting back afterwards.
Stallbell checks for missed and stuck runs once a minute, so those alerts arrive within a minute or so of the deadline. A failure ping is handled as soon as it arrives. In a single test on 19 Oct 2026, the Failed run email arrived about 6 seconds after the wrapper started. That's one observation, not a promise.
Crontab gotchas that break the ping itself
$? must come straight after the job. backup.sh > /dev/null; echo done; curl …/$? reports the exit code of echo (0), not of the backup. Keep the curl directly after the command you care about, or use the wrapper.
Don't use && for the ping. backup.sh && curl … only pings on success. On failure, nothing is sent, so the only alert you'll get is a missed run after the grace period, not a failure right away.
Escape % in the crontab. Cron turns an unescaped % into a newline and feeds the rest of the line to the command's stdin, so date +%F in a crontab cuts the line short and the curl after it never runs. Write date +\%F, or move the command into a script (crontab(5)).
Cron has a short PATH. Debian and Ubuntu's cron starts jobs with PATH=/usr/bin:/bin. A command that works in your shell can fail with "not found" (exit code 127) under cron. The one-liner reports that as a failure, which is how you'll find out. Use full paths, or set PATH= at the top of the crontab.
Match the timezone. Debian and Ubuntu's cron runs on the server's timezone and doesn't support a per-crontab timezone. Cronie (Fedora, RHEL and friends) accepts CRON_TZ= at the top of the crontab. In Stallbell, each cron-schedule monitor has a Schedule timezone: your account timezone (set from your browser when you sign up), UTC, or a named zone. Pick the one your server's cron uses. The monitor page lists the next three expected runs in that zone, so you can check they line up with when the job really runs.
Keep the ping URL private. If your crontab lives in a public repo, put the URL in an environment variable or a root-only file and reference that instead.
FAQ
Do I need the wrapper, or is the one-liner enough? The one-liner catches failures and jobs that never run. Add the wrapper for any job that could hang or that runs for more than a few minutes, so you hear about it within the Stuck after time instead of on the next schedule.
Will a Stallbell outage break my cron job? No. The ping is a separate curl call with a 10-second limit, after the job (one-liner) or around it (wrapper). If it fails, curl prints an error and your job carries on. You'd see missed-run alerts instead of silence.
What does Stallbell store? The check-in event and time, the exit code, the run_id and duration_ms if you send them, and any msg (up to 500 characters) or output (the first 2 KB). The one-liner and the wrapper send no output. To see what a single run sent, click it under Recent runs on the monitor page: the Run drawer shows its status, times, duration, exit code, message, and the first 500 characters of any output.
Can I catch a job that "succeeds" but produces nothing? Yes. Send the job's output in the finish ping as output. If it's empty or only whitespace, Stallbell opens an empty-output warning. You can also require a phrase, or require valid JSON, in the monitor settings. Sending output is up to you: the one-liner and wrapper above don't send any, so a quiet job won't trigger this.
Where do alerts go? To your account email by default. You can add other email addresses, a Slack incoming webhook or a signed webhook under Channels. Email, Slack and webhooks are included on every plan, Free included.
What does it cost? There's a Free plan with no card, and it gets every check. On a fixed interval, Free checks as often as every 15 minutes, Pro every 5 minutes and Scale every minute. While Stallbell is in beta, billing is off and every account gets Pro limits with every-minute checks. Plans and limits are on the pricing page.
Start with the job you'd least like to find broken
Pick the cron job whose failure would cost you the most (usually the backup) and add the one-liner today. It takes a minute, and from then on, if that job fails, hangs or stops running, you'll get an email.
Related: Why cron jobs fail silently · How to check if a cron job ran · Detect stuck jobs · What is heartbeat monitoring?
Ready-made settings for two common cron jobs: Postgres nightly backup · certbot renewal