Common cron schedule mistakes
Most cron mistakes come from an expression that is valid but does not mean what you intended, and you can catch each one by reading it back in words. A few mistakes cause most of the surprises, and each is easy to catch if you read the expression back in words.
Mistake 1: 5 when you meant */5
The expression 5 * * * * means at 5 minutes past every hour, which is once an hour. To run every five minutes you need */5 * * * *. A bare number is a fixed time and a step is a repeat.
Mistake 2: day of month and day of week together
When you fill in both the day of the month and the day of the week, standard cron runs the job when either matches, not when both do.
So 0 0 13 * 5 runs at 12:00 AM on the 13th of every month and also on every Friday. It does not mean only Friday the 13th. If you need both conditions, run the job daily and check the date inside it.
Mistake 3: a step that does not divide evenly
Steps count from the start of the range. */2 in the hour field runs at hours 0, 2, 4 and so on, then starts again at midnight. A step such as */7 in the minute field runs at 0, 7, 14 and so on up to 56, and then jumps back to 0, so the last gap is shorter than the others.
Mistake 4: forgetting the time zone
The schedule uses the clock of the machine or service running it. A job meant for 9:00 AM local time can fire hours away from that when the server uses another zone.
A habit that prevents most of these
- Read the expression back in words before you save it.
- Look at the next few run times and check they are the ones you expect.
- Test the job at a time close to now before you rely on it.
Cron Expression Generator: Paste an expression to get a plain-words explanation and the next run times.