Automation & Operations3 min read
How to Create a Cron Schedule
Cron runs a job on a schedule, and its five fields put people off for no good reason. Here is what each one means and how to build or read an expression.
KLYRO TeamPublished
Cron is the scheduler almost everything uses: servers, hosting panels, backup tools, deployment pipelines and most automation platforms. A cron expression is five values separated by spaces, and it says when a job should run.
It looks cryptic and it is not. Once you know which field is which, you can read almost any schedule at a glance.
The five fields
Always in this order, always separated by a single space.
┌───────────── minute (0 - 59)
│ ┌─────────── hour (0 - 23)
│ │ ┌───────── day of month (1 - 31)
│ │ │ ┌─────── month (1 - 12)
│ │ │ │ ┌───── day of week (0 - 6, Sunday is 0)
│ │ │ │ │
0 9 * * 1-5The four symbols
| Symbol | Means | Example |
|---|---|---|
| * | Every value in this field | * * * * * runs every minute |
| , | A list of specific values | 0 9,17 * * * runs at 09:00 and 17:00 |
| - | A range | 0 9 * * 1-5 runs weekdays only |
| / | A step within a range | */15 * * * * runs every 15 minutes |
Schedules you will actually use
| Expression | When it runs |
|---|---|
| 0 * * * * | Every hour, on the hour |
| */15 * * * * | Every 15 minutes |
| 0 2 * * * | Every day at 02:00 |
| 0 9 * * 1-5 | Weekdays at 09:00 |
| 30 3 * * 0 | Sundays at 03:30 |
| 0 0 1 * * | Midnight on the first of every month |
How to read an expression you were given
Paste it in
Any standard five-field expression. If it cannot be parsed, the tool says so rather than guessing at what you might have meant.
Read the plain-English line
The explanation is derived from the parsed expression itself, so a schedule you pasted and one you built are read by exactly the same code.
Check the next few runs
This is the part that catches mistakes. An expression that looks right and whose next run is three weeks away is telling you something.
Common mistakes
- Setting the day of month and the day of week together. On most cron implementations
0 0 1 * 1runs on the 1st *or* on Mondays, not on Mondays that fall on the 1st. Leave one of them as*. - Forgetting the server's timezone. Cron uses the machine's clock. A job set for 09:00 on a UTC server runs at 10:00 British Summer Time.
- Running everything on the hour. If a dozen jobs all fire at
0 * * * *, they compete. Spread them across the hour. - Scheduling something for 31 February.
0 0 31 2 *is valid and will never run. - Assuming the previous run finished. Cron starts a job on schedule whether or not the last one is still going.
Questions
- What is the shortest interval cron supports?
- One minute. Standard cron has no seconds field. If you need something more frequent than that, cron is the wrong tool.
- Do the six-field expressions I have seen work here?
- This builder handles the standard five-field format. Some schedulers add a seconds field at the front or a year at the end; those are extensions, not standard cron.
- Is 0 the same as Sunday or Monday?
- Sunday. Both
0and7mean Sunday in most implementations, which is a common source of off-by-one schedules.