Vaultools
Menu

Cron expression

A cron expression is a compact schedule of five space-separated fields (minute, hour, day of month, month and day of week) that tells the cron daemon, and many schedulers modeled on it, when to run a job. Different systems add fields or change the rules, so the same text can mean different things.

Open the Cron Expression Explainer Runs in your browser

The five fields

┌───────── minute        (0-59)
│ ┌─────── hour          (0-23)
│ │ ┌───── day of month  (1-31)
│ │ │ ┌─── month         (1-12 or JAN-DEC)
│ │ │ │ ┌─ day of week   (0-7 or SUN-SAT, 0 and 7 are Sunday)
│ │ │ │ │
* * * * *

The cron daemon wakes every minute and runs each job whose fields all match the current time. 30 9 * * 1-5 means minute 30, hour 9, any day of the month, any month, Monday through Friday: 09:30 on weekdays.

Each field accepts a few building blocks:

SyntaxMeaningExample
*Every value* * * * * runs every minute
a,bA list0,30 is minutes 0 and 30
a-bAn inclusive range9-17 is hours 9 to 17
*/n or a-b/nA step*/15 is every 15 minutes

Most implementations also accept @daily, @hourly, @weekly, @monthly and @yearly as shortcuts.

Two rules that surprise people

Dialects

Standard five-field cron is used by crontab, Kubernetes CronJobs and GitHub Actions schedules. Other systems borrow the idea but change it. Quartz and Spring put a seconds field first and add L (last), W (nearest weekday) and # (nth weekday of the month). AWS EventBridge uses six fields ending in a year. Quartz and AWS number the days of the week from Sunday = 1 and require ? in one of the two day fields, while Spring keeps cron’s 0-7 numbering and requires both day fields to match. An expression copied between these systems can run at the wrong time without any error.

Common pitfalls

References

Ads on this page

Non-personalized ads help keep Vaultools free — Google decides where they appear on the page.

Go Pro to remove them →