How to debug cron jobs: logging, email output, and troubleshooting silent failures
Cron's default failure mode is silence. If a job fails, cron sends the output to the user's local mail spool, which on most modern systems goes unread because nothing is configured to deliver it. The result: your job has been failing for weeks and you had no idea. Fixing this means redirecting output somewhere you'll actually see it.
How this is calculated
Three debugging strategies work. First, redirect STDOUT and STDERR to a log file: 0 * * * * /path/to/script >> /var/log/myjob.log 2>&1. Second, set MAILTO=you@example.com at the top of your crontab to get email on every execution. Third, wrap the command in a script that logs the start time, exit code, and runtime duration. The most common silent failure cause is missing environment: cron runs with a minimal PATH (typically /usr/bin:/bin) and no shell profile loaded. Always use absolute paths to executables in cron commands, or set PATH explicitly in the crontab.
Verdict
Never deploy a cron job without output capture. At minimum, redirect to a log file. For production, add structured logging with timestamps, exit codes, and runtime. And always use absolute paths or set PATH in the crontab.
More Cron scenarios
Related guides
Frequently asked questions
What is a Cron Job?
What do the 5 parts of a cron expression mean?
What does the asterisk (*) mean in Cron?
How do I run a task every 5 minutes?
Related tools
Unix Timestamp
Convert between Unix timestamps and human-readable dates.
Use tool ➜CHMOD Configurator
Calculate Linux file permissions using checkboxes, octal numbers, or symbolic notation.
Use tool ➜Text Encoding Converter
Convert between Text, Base64, Binary, Hexadecimal, and Decimal formats.
Use tool ➜