Cron logging & logs
When a cron job silently fails, it's painful to debug. Good logging makes it obvious when jobs run, what they did, and why they might have failed.
Redirecting cron job output to a log file
The easiest way to log cron jobs is to redirect stdout and stderr to a file from the crontab line itself:
# Append output and errors to a log file 0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
The 2>&1 part sends errors (file descriptor 2) to the same place as standard output (file descriptor 1).
Where cron logs show up on Linux
Depending on your distribution and init system, cron activity may be logged to different places:
/var/log/cronor/var/log/cron.log/var/log/syslog(look for lines mentioningCRON).journalctl -u cronorjournalctl -u crondon systemd-based systems.
These logs usually include when jobs started, which command ran, and which user the job ran as—but not the job's output unless you capture it yourself.
Email notifications with MAILTO
Many cron implementations can email job output to a recipient if you're running a local MTA (mail transfer agent). Set the MAILTO variable at the top of your crontab:
MAILTO=alerts@example.com 0 8 * * * /usr/local/bin/daily-report.sh
The exact behavior depends on how email is configured on the server. In many modern setups, redirecting to structured logs is more reliable.
Logging cron jobs in containers and cloud platforms
In container-based environments, "logs" are usually collected from stdout/stderr rather than log files.
- Kubernetes CronJobs: job pod logs are visible via
kubectl logsand your cluster's logging pipeline. - GitHub Actions: job logs show up in the Actions UI and can be exported via the API.
- AWS EventBridge: targets such as Lambda or ECS write to CloudWatch Logs by default.
The pattern is the same: make sure your cron-style jobs log meaningful messages to stdout/stderr, and let the platform do the rest.
Troubleshooting failing cron jobs
- Check that the job actually runs by adding a simple
echoline and confirming it appears in the logs. - Use absolute paths to binaries and scripts; cron's environment has a minimal
$PATH. - Capture both stdout and stderr so you don't miss error messages.
- Verify that your cron expression is correct—our cron reference pages and visual calendars can help.