Detect Cron Job Wrong Exit Code: Validate Exit Codes
Your cron job returns exit code 0 (success) when it should fail, or non-zero when it should succeed. Learn how to detect and handle wrong exit codes.
Why Exit Codes Can Be Wrong
Scripts can return wrong exit codes:
- Script catches all exceptions and exits with 0
- Command succeeds but produces wrong results
- Script doesn't check command exit codes
- Error handling sets wrong exit codes
- Pipes mask exit codes
Don't trust exit codes alone—verify that work was actually completed.
Solution: Validate Results, Not Just Exit Codes
After running commands, verify that expected results exist. Check file sizes, validate output content, confirm data was written. The validation must be inside your script.
Bash Example: Verify Results
#!/bin/bashBACKUP_FILE="/backups/db.sql"# Run backuppg_dump mydb > "$BACKUP_FILE"EXIT_CODE=$?# Get backup file size (0 if file doesn't exist or is empty)FILE_SIZE=$(stat -f%z "$BACKUP_FILE" 2>/dev/null || stat -c%s "$BACKUP_FILE" 2>/dev/null || echo 0)# Single ping with file size in payload# In DeadManPing panel: set validation rule "size" > 0# Panel will automatically detect if backup file is empty even though exit code was 0curl -X POST "https://deadmanping.com/api/ping/backup?size=$FILE_SIZE"Python Example: Validate After Execution
import subprocessimport osimport requestsimport sysbackup_file = "/backups/db.sql"# Run backupresult = subprocess.run(['pg_dump', 'mydb'], stdout=open(backup_file, 'w'))# Get backup file size (0 if file doesn't exist or is empty)file_size = os.path.getsize(backup_file) if os.path.exists(backup_file) else 0# Single ping with file size in payload# In DeadManPing panel: set validation rule "size" > 0# Panel will automatically detect if backup file is empty even though exit code was 0requests.post(f"https://deadmanping.com/api/ping/backup?size={file_size}")Monitoring Wrong Exit Codes
After adding result validation to your scripts, use a dead man switch to monitor whether validation completed successfully. If your script detects wrong exit codes and exits with error, the ping never arrives, and you get an alert.
Working Examples
See complete, working code examples in our GitHub repository:
View Examples on GitHub →Start Detecting Wrong Exit Codes
DeadManPing monitors whether your exit code validation completes. Set up monitoring in 2 minutes, get alerts when jobs return wrong exit codes.
Start Monitoring FreeRelated Articles
Learn more about cron job monitoring and troubleshooting:
Cron Job Exit Code Not Zero
How to detect when cron jobs exit with non-zero exit codes.
Cron Job Exit Status Check
How to check cron job exit status and verify jobs completed successfully.
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.