How to monitor cron jobs

To monitor a cron job, add an HTTP check-in to the end of its crontab line. The check-in reports whether the run succeeded and carries the job’s cron expression, so Alert51 knows when the next run is due. You get a cron job failure alert as soon as a run reports failure, and an alert when a cron job doesn’t run by its deadline.

Why cron jobs fail silently

cron starts commands and forgets them. Output goes to local mail that nobody reads, a job that exits non-zero looks the same as one that succeeded, and a job that never starts produces nothing at all: a disabled crontab, a server that was replaced, or a typo in the schedule. Watching for an error message cannot catch a run that never happened. Heartbeat-style monitoring can: the job reports in, and silence becomes the signal.

1. Create a token and store it on the server

Sign up, verify your email address, then create an API token under API tokens in the dashboard. The secret is shown once. Put it in a file only root can read, for example /etc/alert51.env with mode 600. Details: API token authentication.

/etc/alert51.env
export ALERT51_URL="https://api.alert51.com"
export ALERT51_TOKEN="a51_xxxxxxxx_your-secret"

2. Monitor a crontab job with curl

This line runs sync-reports.sh every 30 minutes and reports the result either way. The if turns the exit code into success or failure, and --max-time 10 keeps a slow network from holding the job.

crontab -e
*/30 * * * * . /etc/alert51.env; if /opt/jobs/sync-reports.sh; then s=success; else s=failure; fi; curl -fsS --max-time 10 -H "Authorization: Bearer $ALERT51_TOKEN" -H 'Content-Type: application/json' -d "{\"project\":\"production\",\"job\":\"sync-reports\",\"status\":\"$s\",\"cron\":\"*/30 * * * *\",\"timezone\":\"UTC\",\"graceSeconds\":600}" "$ALERT51_URL/v1/check-ins"
  • The cron field must match the schedule at the start of the line.
  • Set timezone to the time zone the cron daemon uses (often the server’s system zone, UTC here). Otherwise Alert51 expects the run at the wrong hour.
  • crontab treats % as a newline. If the command needs one, move it into a script, as in the backup job guide.
  • graceSeconds is how long past the scheduled time a run may report before it counts as missed.

Prefer a script file or application code? The same check-in works from a shell script or from Node.js fetch; see the Node.js example.

3. Run it once and check the result

Run the command by hand. The first check-in creates the project production and the monitor sync-reports, stores the schedule and sets the first deadline. The response looks like this (taken from a backup job run on our test account):

Response
{
  "monitorId": "45656f16-fe18-4fcf-9392-defd48043c1a",
  "project": "production",
  "job": "db-backup",
  "created": true,
  "checkIn": {
    "id": "17e5d9f9-e64a-48f6-95a2-1cecb3314085",
    "status": "success",
    "receivedAt": "2026-11-23T00:44:07.609Z",
    "slotAt": "2026-11-22T03:00:00.000Z",
    "outcome": "applied",
    "late": true
  },
  "schedule": {
    "cron": "0 3 * * *",
    "timezone": "UTC",
    "graceSeconds": 1800,
    "changed": false
  },
  "monitorStatus": "up",
  "nextRunAt": "2026-11-23T03:00:00.000Z",
  "deadlineAt": "2026-11-23T03:30:00.000Z",
  "incident": null
}

created: true means the monitor is new. late: true is expected for a manual run outside the schedule. deadlineAt is when Alert51 will open a missed incident if the next run does not report.

Alert if a cron job doesn’t run

After each check-in, Alert51 computes the next run from the cron expression and adds the grace period. With */30 * * * * and 600 seconds of grace, a run that reports at 10:00 sets the next run to 10:30 and the deadline to 10:40. If nothing arrives by 10:40, a missed incident opens and your channels are notified. Later missed slots stay in the same incident; the next successful check-in resolves it.

Cron job failure alerts

A check-in with "status": "failure" opens an incident at once, without waiting for the deadline. Alerts go to your verified email and linked Telegram chats on every plan, and to signed webhooks on Startup and above. Test it by replacing the job with false once.

If the check-in is rejected

  • 401: the token is wrong or revoked.
  • 403 email_not_verified: verify your email address first.
  • 403 quota_exceeded: the new monitor or project is over your plan limit. Free includes three monitors in one project.
  • 400: a field is invalid, for example a cron expression with a typo. The message names the field.

curl -fsS prints these errors to stderr, so they reach cron’s mail or your log. All codes: errors.

Confirm it’s you

Security changes need a sign-in from the last 10 minutes. Confirm once and the change continues automatically.