Exit codes and failure signals

On this page

Every command ends with an exit status from 0 to 255. Zero means success and anything else means failure. Send it to CronMissed as the last part of the ping URL and a failed job alerts within seconds, instead of waiting for the missing success ping to time out.

How do I send the exit status?

crontab
/usr/local/bin/backup.sh; curl -fsS --retry 5 https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10/$?

The semicolon (and not &&) runs the ping whatever the job did, and $? holds the job's status. A status of 0 is a success ping; any other number marks the check down at once and records the number. /fail does the same without a number. Both accept a POST body with the error output.

Which codes mean what?

CodeUsual meaning
0Success
1General error; also the usual code for "found nothing" in some tools
2Misuse of a shell built-in or a usage error
126The command was found but could not be run, often a missing execute bit
127Command not found, the classic sign of a PATH problem under cron
128 + NThe process was killed by signal N; 137 means kill -9 and 143 means SIGTERM

Tools define their own codes too. restic, BorgBackup and rsync each document codes for partial success, and a wrapper can map the ones you accept to 0.

Which traps hide a failure?

  • A pipeline reports the status of its last command. Use set -o pipefail in bash, or check PIPESTATUS.
  • A script that ends with a harmless command, such as echo, exits 0 whatever happened before it. Add set -e, or exit with the real status.
  • A shell function that swallows errors with || true is a success by design.
  • A PowerShell script sets no exit code unless you do; use exit $LASTEXITCODE.

Sources

Questions and answers

What happens to a status above 255?
Exit statuses are one byte, so they wrap around: 256 becomes 0. Keep your own codes between 1 and 125.
Can I send a message with the failure?
Yes. POST the last 100 kB of output to the same URL; it is kept with the ping and included in the alert for failures.
Know the moment a job goes quiet

Create a check, add one curl to the job, and CronMissed alerts you when a ping is late or reports a failure.

Start monitoring