Capture and Report Cron Job Exit Codes

Common Errors

The Problem

Cron ignores exit codes entirely. A job that exits with code 1 (failure) is treated identically to code 0 (success). No alert, no log, nothing.

The Solution

Capture the exit code with $? in shell, or use CronRabbit's exit code URL feature to automatically report the status.

How CronRabbit Exit Codes Work

Append the exit code to your ping URL: /your-id/0 for success, /your-id/1 for failure. CronRabbit treats any non-zero code as a failure and triggers an alert.

Code Examples

Report exit code to CronRabbit

Bash
# Simple exit code reporting
0 2 * * * /scripts/backup.sh; curl -fsS -m 10 --retry 5 --retry-all-errors https://ping.cronrabbit.com/your-id/$?

# With explicit handling
0 2 * * * /scripts/backup.sh && curl -fsS -m 10 --retry 5 --retry-all-errors https://ping.cronrabbit.com/your-id || curl -fsS -m 10 --retry 5 --retry-all-errors https://ping.cronrabbit.com/your-id/fail

Ready to Monitor Your Cron Jobs?

Create your free account and add your first monitor in under 5 minutes. No credit card required.