A cron expression can be perfectly valid and still run at the wrong time. No error, no warning. The job just fires on a day you didn't expect, or hours early, or twice. Here are the three mistakes behind most of these surprises, and how to avoid each one.
Quick refresher: a cron expression has five fields.
ββββββββββββββ minute (0β59) β ββββββββββββ hour (0β23) β β ββββββββββ day of month (1β31) β β β ββββββββ month (1β12) β β β β ββββββ day of week (0β6, Sunday = 0) β β β β β 0 9 * * 1-5
Enter fullscreen mode
Exit fullscreen mode
1. Setting both day fields (the OR rule)
What does this mean?
0 0 13 * 5
Enter fullscreen mode
Exit fullscreen mode
Most people read it as "midnight on Friday the 13th". Cron reads it as "midnight on the 13th of every month, or midnight on any Friday".
When both day fields are restricted (neither is * ), classic cron runs the job when either one matches, not both.β¦