How to Read a Cron Expression
A cron expression is five fields separated by spaces, and once you know the order it stops being cryptic. The Cron Expression Parser will tell you in plain words what any expression schedules.
The five fields
Left to right: minute (0 to 59), hour (0 to 23), day of month (1 to 31), month (1 to 12), day of week (0 to 6, Sunday being 0).
An asterisk means every value of that field. So five asterisks means every minute of every hour of every day - the busiest schedule there is, and a common accident.
Read an expression by saying each field aloud in order. Thirty, nine, asterisk, asterisk, one: at minute thirty of hour nine, any day of the month, any month, on Monday. Half past nine every Monday.
The one mistake everybody makes
Leaving the minute field as an asterisk when you meant a specific minute. An expression of asterisk, nine, asterisk, asterisk, asterisk does not run at nine o'clock. It runs at every minute of the nine o'clock hour - sixty times.
Say it in the right order and the error is obvious. The fields are not in the order you say a time in English, and that mismatch is the whole problem.
Slashes, commas and ranges
A slash means a step. Zero-slash-fifteen in the minute field is every fifteen minutes from zero, so at zero, fifteen, thirty and forty-five. Asterisk-slash-two in the hour field is every second hour.
A comma lists values: one, fifteen in the day-of-month field means the first and the fifteenth. A hyphen is a range: nine-to-seventeen in the hour field is every hour from nine to five.
The surprise is the two day fields together. When both day of month and day of week are restricted, most implementations run the job if either matches, not both. So the fifteenth and Monday means every fifteenth and every Monday, which is not what it reads like.
Timezones and missing runs
Cron uses the server's local time unless told otherwise, so a job scheduled for midnight runs at the server's midnight. That matters when the server is in a different country from you, and it matters twice a year when the clocks change - an hour that is skipped in spring means a job scheduled inside it does not run at all, and an hour repeated in autumn can run a job twice. Scheduling anything important slightly off the hour avoids the worst of it, and if the job must run exactly once, make it safe to run twice.
Common questions
What does a sixth field mean?
Some implementations add seconds at the front or a year at the end. Check which, because it shifts every other field.
Can I use day names?
Many versions accept three-letter abbreviations for days and months, which is far more readable. Not all do.
How do I run something once a month?
Fix the minute, the hour and the day of month, and leave month and day of week as asterisks.
What happens if the job is still running?
Cron starts another one. Overlapping runs are the caller's problem, so use a lock if that matters.
Got an expression you are not sure about?