Cron Job Exit Code Not Zero: Detect Failures
Your cron job exits with a non-zero exit code, indicating failure. Learn how to detect and handle exit codes properly.
Understanding Exit Codes
Exit codes indicate whether a command succeeded or failed:
- Exit code 0 - Success
- Exit code 1 - General error
- Exit code 2 - Misuse of shell command
- Exit code 126 - Command cannot execute
- Exit code 127 - Command not found
- Exit code 130 - Script terminated by Ctrl+C
- Any non-zero - Failure
Cron doesn't alert you when jobs exit with non-zero codes. You need to check exit codes explicitly.
How to Check Exit Codes
Always check exit codes after running commands. The check must be inside your script, not in the cron line, because you need to handle the exit code and send appropriate pings.
Bash Example: Check Exit Code
#!/bin/bashset -e # Exit immediately on error# Run command and capture exit code./backup.shEXIT_CODE=$?# Single ping with exit code in payload# In DeadManPing panel: set validation rule "exit_code" == 0# Panel will automatically detect if exit code is non-zero and alertcurl -X POST "https://deadmanping.com/api/ping/backup-daily?exit_code=$EXIT_CODE"Bash Example: Check Multiple Commands
#!/bin/bashFAILED=0# Run multiple commands and check each./step1.sh || FAILED=1./step2.sh || FAILED=1./step3.sh || FAILED=1# Single ping with step completion data in payload# In DeadManPing panel: set validation rule "failed_steps_count" == 0# Panel will automatically detect if any steps failedcurl -X POST "https://deadmanping.com/api/ping/multi-step?failed_steps_count=$FAILED"Python Example: Check Exit Code
import subprocessimport sysimport requests# Run command and check exit coderesult = subprocess.run(['./backup.sh'], capture_output=True)# Single ping with exit code in payload# In DeadManPing panel: set validation rule "exit_code" == 0# Panel will automatically detect if exit code is non-zero and alertrequests.post(f"https://deadmanping.com/api/ping/backup-daily?exit_code={result.returncode}")Node.js Example: Check Process Exit Code
const { execSync } = require('child_process');const https = require('https');let exitCode = 0;try { // execSync throws on non-zero exit code execSync('./backup.sh', { stdio: 'inherit' });} catch (error) { exitCode = error.status || 1;}// Single ping with exit code in payload// In DeadManPing panel: set validation rule "exit_code" == 0// Panel will automatically detect if exit code is non-zero and alerthttps.request(`https://deadmanping.com/api/ping/backup-daily?exit_code=${exitCode}`, { method: 'POST' }).end();Bash Example: Pipe Failures
#!/bin/bashset -o pipefail # Catch failures in pipes# Pipe can fail but still return 0pg_dump mydb | gzip > backup.sql.gzEXIT_CODE=$?# Single ping with exit code in payload# In DeadManPing panel: set validation rule "exit_code" == 0# Panel will automatically detect if exit code is non-zero and alertcurl -X POST "https://deadmanping.com/api/ping/backup-daily?exit_code=$EXIT_CODE"Monitoring Exit Codes
After adding exit code checks to your scripts, use a dead man switch to monitor whether checks completed successfully. If your script detects a non-zero exit code and exits with error, the ping never arrives, and you get an alert.
Include exit codes in your ping payload so you can track what types of failures occur and identify patterns.
Working Examples
See complete, working code examples in our GitHub repository:
View Examples on GitHub →Start Monitoring Exit Codes
DeadManPing monitors whether your exit code checks complete. Set up monitoring in 2 minutes, get alerts when jobs exit with non-zero codes.
Start Monitoring FreeRelated Articles
Learn more about cron job monitoring and troubleshooting:
Cron Job Exit Status Check
How to check cron job exit status and verify jobs completed successfully.
Detect Cron Job Wrong Exit Code
How to detect when cron jobs return wrong exit codes.
Cron Job Failed? How to Detect & Fix in 5 Min
Step-by-step guide to detect why your cron failed, fix it, and get alerts so it never happens again.
Verify Cron Job Completed
How to verify that cron jobs completed successfully.