Preventing Cron Job Failures Across Timezones and UTC
Scheduling a daily billing script at 0 2 * * * (2:00 AM) on a server configured in a regional timezone causes the job to disappear completely in spring and run twice in autumn. Every cron daemon follows its host timezone unless you set UTC explicitly.
Three Rules for Reliable Cron Jobs
- Set
CRON_TZ=UTCat the top of your crontab: Running background infrastructure in UTC guarantees 86,400-second days with zero DST jumps. - Use file locks or database idempotency keys: Wrap long scripts with Linux
flockso an overlapping run never processes duplicate invoices. - Handle business hours in application logic: If a report must arrive at 9:00 AM New York time, trigger an hourly UTC cron job that checks
America/New_Yorkinside Python or Node.js before sending.
# Explicit UTC crontab example with overlap lock
CRON_TZ=UTC
0 6 * * * /usr/bin/flock -n /tmp/billing.lock /usr/bin/python3 /opt/jobs/billing.py