bitlvl
EN

Cron expression explainer

Type the five fields of a crontab entry. You get the schedule in plain English and the next ten times it would fire, in the time zone of your choice.

Crontab syntax

┌───────────── 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)
│ │ │ │ │
* * * * *  command to run
SyntaxMeaningExample
*Every value* * * * *every minute
5Exactly this value5 0 * * *00:05 daily
1-5A range0 9 * * 1-509:00 on weekdays
*/15Every n-th value*/15 * * * *every 15 minutes
1,15A list0 0 1,15 * *midnight on the 1st and 15th
8-18/2Step within a range0 8-18/2 * * *every 2 hours from 08:00 to 18:00
@dailyMacro@dailysame as 0 0 * * *

The day-of-month / day-of-week trap

If both the day-of-month and day-of-week fields are restricted, standard cron runs when either matches, not both. 0 0 13 * 5 fires on every 13th and every Friday, not only on Friday the 13th. The explainer flags this case.

Time zones and DST

Cron runs in the system time zone of the machine (or the CRON_TZ / TZ variable where supported). On the night clocks go forward, a job scheduled for 02:30 may not run at all; when they go back, it may run twice. Jobs that must run exactly once a day are safest between 03:00 and 23:00, or in UTC. The run-time list above uses real calendar rules for the zone you choose, so you can check a DST night directly.

Other things to know

  • Cron has one-minute resolution. For seconds, use a systemd timer or a loop in the job.
  • The environment is minimal: set PATH in the crontab or use absolute paths, and redirect output or it is mailed to you.
  • % in the command field is a newline unless escaped as \%, which bites date +%F.
  • Six-field expressions with a seconds column are Quartz/Spring syntax, and non-standard L, W and # are Quartz too. Plain crontab does not accept them.

Questions

How do I run a cron job every 5 minutes?

*/5 * * * *. For every 5 minutes during working hours only: */5 9-17 * * 1-5.

How do I run something at midnight every day?

0 0 * * *, or the macro @daily. For 00:30 use 30 0 * * *.

How do I schedule the last day of the month?

Standard cron cannot express it directly. Run on days 28–31 and let the script check whether tomorrow is the 1st: 0 0 28-31 * * [ "$(date -d tomorrow +%d)" = "01" ] && /path/to/job.

Is day of week 0 or 7 for Sunday?

Both. 0 and 7 are Sunday in most cron implementations; Monday is 1. Names (sun, mon) are also accepted and are harder to get wrong.

Why did my job run at the wrong time?

Almost always the time zone: the server is in UTC and you expected local time, or vice versa. Check with date on the server, or set CRON_TZ=Europe/Belgrade at the top of the crontab where supported (cronie, Vixie cron).

What is the difference between cron and systemd timers?

Timers can run on calendar expressions with seconds, catch up on missed runs after a reboot (Persistent=true), log to the journal and depend on other units. Cron is simpler and universal. Both are fine for ordinary scheduled jobs.