12 Cron Job Best Practices for Production (2026)
Cron is deceptively simple. A single misconfigured line can silently skip a critical job for weeks. These practices come from running scheduled work in production.
Reliability
- Make jobs idempotent — running twice should be safe, because retries and overlaps happen.
- Prevent overlapping runs with a lock (flock) so a slow job never stacks on itself.
- Set a timeout (timeout 30m ...) so a hung job fails instead of running forever.
- Use absolute paths — cron’s PATH is minimal and not your shell’s.
- Load the environment explicitly; do not assume profile variables exist.
0 3 * * * /usr/bin/flock -n /tmp/backup.lock timeout 30m /usr/local/bin/backup.shObservability
- Always capture output: >> /var/log/backup.log 2>&1.
- Exit with a non-zero status on failure so wrappers can detect it.
- Emit a heartbeat ping on success so you know it actually ran.
- Track execution time to catch slow degradation early.
Operations
- Pin the timezone explicitly for time-sensitive jobs.
- Version your crontab in source control; do not edit it ad hoc on the box.
- Alert to a channel a human actually watches — not a log file.
Monitoring in one line
CronGuard adds production-grade monitoring to any cron job with a single ping. Define the expected schedule and get instant SMS, WhatsApp, Slack, Telegram or email alerts when a run is missed. Free to start, nothing to install.
Stop losing sleep over silent failures
CronGuard alerts you within minutes when a scheduled job fails to check in. No agent to install. Free to start.
Start Monitoring Free