Cron Job Returns Success But Fails: Detect False Success
Your cron job exits with code 0 (success), but it didn't actually complete its work. Learn how to detect false success.
The Problem: False Success
Scripts can exit with success code (0) even when they fail:
- Script catches all exceptions but doesn't verify results
- Command succeeds but produces empty or wrong output
- Network request returns 200 but contains error message
- File operations succeed but files are empty or corrupted
- Database query runs but returns no results when data expected
- Script completes but doesn't perform intended work
Exit code alone doesn't verify that work was actually completed. You need to validate results.
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, or verify API responses. The validation must be inside your script, not in the cron line.
Bash Example: Verify Backup File Created
#!/bin/bashBACKUP_FILE="/backups/db-$(date +%Y%m%d).sql"# Run backup (might exit 0 even if it fails)pg_dump mydb > "$BACKUP_FILE"# 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 (or >= 1024 for minimum size)# Panel will automatically detect if backup file is empty even though exit code was 0curl -X POST "https://deadmanping.com/api/ping/backup-daily?size=$FILE_SIZE"Python Example: Validate API Response
import requestsimport sys# API call might return 200 but with errorresponse = requests.get("https://api.example.com/data")# Extract response data for payloadhas_error = Falsedata_count = 0try: data = response.json() has_error = "error" in data data_count = len(data.get("data", []))except: has_error = True# Single ping with response data in payload# In DeadManPing panel: set validation rules:# - "status_code" == 200# - "has_error" == False# - "data_count" > 0# Panel will automatically detect violations and alertrequests.post(f"https://deadmanping.com/api/ping/api-job?status_code={response.status_code}&has_error={has_error}&data_count={data_count}")Node.js Example: Verify Database Query Results
const { execSync } = require('child_process');const https = require('https');// Query might succeed but return no rowsconst output = execSync('psql -c "SELECT COUNT(*) FROM users"', { encoding: 'utf8' });// Parse count from outputconst match = output.match(/(\d+)/);const count = match ? parseInt(match[1]) : 0;// Single ping with count in payload// In DeadManPing panel: set validation rules:// - "count" > 0 (to detect empty results)// - "count" >= 10 (minimum expected count, optional)// Panel will automatically detect if count violates ruleshttps.request(`https://deadmanping.com/api/ping/db-check?count=${count}`, { method: 'POST' }).end();Bash Example: Verify Multiple Conditions
#!/bin/bashset -e# Run sync (might exit 0 even if sync fails)rsync -avz /data/ user@server:/backup/# Verify sync actually worked by checking remote fileREMOTE_COUNT=$(ssh user@server "find /backup -type f | wc -l")LOCAL_COUNT=$(find /data -type f | wc -l)# Calculate count differenceDIFF=$(( LOCAL_COUNT - REMOTE_COUNT ))DIFF_ABS=${DIFF#-}# Single ping with sync data in payload# In DeadManPing panel: set validation rules:# - "local_count" > 0# - "count_diff" <= 5 (tolerance)# Panel will automatically detect if counts don't matchcurl -X POST "https://deadmanping.com/api/ping/sync-job?local_count=$LOCAL_COUNT&remote_count=$REMOTE_COUNT&count_diff=$DIFF_ABS"Detecting False Success with Validation
After adding result validation to your scripts, use a dead man switch to monitor whether validation completed successfully. If your script detects false success and exits with error code, the ping never arrives, and you get an alert.
Include validation details in your ping payload (e.g., file sizes, record counts) so you can track result quality over time and detect gradual degradation.
Working Examples
See complete, working code examples in our GitHub repository:
View Examples on GitHub →Start Detecting False Success
DeadManPing monitors whether your result validation completes. Set up monitoring in 2 minutes, get alerts when jobs return false success.
Start Monitoring FreeRelated Articles
Learn more about cron job monitoring and troubleshooting:
Curl Success But Wrong Response
How to detect when curl returns success (200) but contains wrong data.
Detect Cron Job Partial Failure
How to detect when cron jobs partially fail—some steps succeed but others fail.
Verify Cron Output
How to verify cron job script output contains expected content.
Silent Cron Failures: How to Detect Them
Detect silent cron job failures that don't log errors.