Cron jobs that succeed but do nothing: catching silent failures

Your cron job exits 0 and every dashboard is green, yet the backup is empty or the sync did nothing. Learn the common causes and how to monitor results, not just runs.

· 6 min read · By the Spot Downtime team

The worst cron failures are not the ones that crash. A crash leaves a log line, an error email or a non-zero exit code. The worst ones exit 0, log nothing unusual, and quietly do no useful work: a backup that dumps an empty file, a sync that processes zero records, a report that sends to nobody.

You find out weeks later, when someone needs the backup. This guide covers how jobs end up in that state and how to make them fail loudly instead.

Why a job can succeed and still be wrong

1. A pipeline hides the real error

In a shell pipeline, the exit code is the last command's by default. If the dump fails, gzip still succeeds on empty input:

bash
# Exits 0 even if pg_dump fails
pg_dump mydb | gzip > backup.sql.gz

# Fail if any stage fails
set -euo pipefail
pg_dump mydb | gzip > backup.sql.gz

Put set -euo pipefail at the top of every Bash script run from cron. -e stops on errors, -u catches unset variables, and pipefail makes a pipeline fail if any stage fails.

2. The script swallows errors

A try/except that logs and continues, a || true added to silence a noisy command, or a wrapper that always ends with exit 0 all turn failures into success. Search your scripts for these before trusting a green status.

3. There was nothing to do, and that is the bug

A job that processes "all new rows since yesterday" will succeed when it finds none. That is correct on a quiet day and a serious problem if a bad filter, a changed column or a time zone shift means it now always finds none. See cron time zone and DST pitfalls for one way that happens.

4. A dependency answered with a success that wasn't

The job calls an API that returns 200 with an error in the body, or returns an empty list when a token expired. The HTTP call succeeded, so the script moved on. Check the content of the response, not just the status code.

5. The output is written somewhere nobody looks

The file lands in a container path that disappears on restart, a directory that was not mounted, or a bucket in the wrong account. The job is fine and the result is gone.

6. It succeeded, then ran again and undid itself

Overlapping runs can truncate or overwrite each other's output. See cron job overlapping runs.

Make the job verify its own result

The fix is to end the script with a check that proves the work happened, and to fail if it did not. Check something that is hard to fake:

  • The output file exists and is larger than a sensible minimum.
  • The number of processed records is above zero when you expect work, or within an expected range.
  • The newest row, file or backup is recent.
  • A restore or a test query against the result works.
bash
#!/usr/bin/env bash
set -euo pipefail

OUT=/backups/db-$(date -u +%F).sql.gz
pg_dump mydb | gzip > "$OUT"

# A real dump of this database is never smaller than 1 MB
SIZE=$(stat -c %s "$OUT")
if [ "$SIZE" -lt 1000000 ]; then
  echo "Backup too small: $SIZE bytes" >&2
  exit 1
fi

Pick the threshold from your own data, and revisit it when the database changes shape.

Monitor from outside the job

A script cannot report that it never started, and a script that is broken may not be able to report anything. Reliable monitoring uses a heartbeat: the job calls a private URL when it finishes successfully, and an external service alerts you if the call does not arrive on schedule.

Place the ping after your verification, so it only fires when the result is good:

bash
#!/usr/bin/env bash
set -euo pipefail

/opt/scripts/backup.sh
/opt/scripts/verify-backup.sh

# Only reached if both succeeded
curl -fsS --retry 3 https://your-heartbeat-url.example/ping

This catches three failures with one check: the job did not run, the job failed, or the job ran but verification failed. The set-up steps are in how to set up a heartbeat monitor, and the wider picture is in how to monitor cron jobs.

Don't ping at the start only

A ping at the start proves cron fired, not that the work finished. If you want both, ping at the start and at the end, and alert when the end is missing.

A short checklist

  1. Add set -euo pipefail to shell jobs, and let exceptions propagate in other languages.
  2. Remove || true and blanket catch blocks unless a failure is truly harmless.
  3. Validate the result: size, count, freshness.
  4. Send the heartbeat only after validation passes.
  5. Test the alert by breaking the job on purpose once.
  6. Periodically restore a backup to prove it works.

If the job does not run at all, start with cron job not running.

Cron expression explainerCheck that your schedule means what you think it means.

Get new guides by email

Practical posts on monitoring, outages, error fixes and on-call, when they're published. No spam.

Unsubscribe from any email with one click. See our privacy policy.

Keep reading