Cron expression explainer
Paste a line from a crontab, such as 30 2 * * 1-5 and a command, or only its five time fields. The page says in words when it runs, lists its next runs, and points out what often surprises people. Below it, build a schedule. It follows the crontab format as cronie documents it, and reads the text in your browser.
Build a schedule
Time fields
0 2 * * 1-5
The five fields
A line holds five time fields, then the command. A line of /etc/crontab or /etc/cron.d also names the user who runs it, between the fields and the command. cron checks every minute, and runs a command when the minute, the hour and the month match and the day matches. If both day fields are restricted, either one is enough: 30 4 1,15 * 5 runs at 4:30 on the 1st and the 15th and on every Friday.
| Place | Field | Values | Also |
|---|---|---|---|
| 1 | Minute | 0 to 59 | |
| 2 | Hour | 0 to 23 | |
| 3 | Day of month | 1 to 31 | |
| 4 | Month | 1 to 12 | or jan to dec |
| 5 | Day of week | 0 to 7 | 0 and 7 are Sunday; or sun to sat |
What a field can hold
| Example | What it means |
|---|---|
* | Every value of the field. |
5 | That value. |
8-11 | A range, both ends included. |
1,15 | A list of values or ranges. |
*/15 | Every 15th value from the start of the field: 0, 15, 30, 45 in minutes. |
0-23/2 | Every 2nd value within the range. |
mon-fri | Names, by their first three letters, for months and days of the week. |
6~15 | A random value within the range, picked when cron reads the crontab (cronie). |
A step counts within its own field only: */23 in the hour field runs at 0:00 and 23:00, not every 23 hours.
Nicknames
| Nickname | When | Same as |
|---|---|---|
@reboot | Once, after the system starts. | |
@yearly | Once a year. | 0 0 1 1 * |
@annually | Once a year. | 0 0 1 1 * |
@monthly | Once a month. | 0 0 1 * * |
@weekly | Once a week. | 0 0 * * 0 |
@daily | Once a day. | 0 0 * * * |
@hourly | Once an hour. | 0 * * * * |
What surprises people
- A
%in the command ends it: what follows goes to the command as input, and each further % becomes a new line. Write\%for a % that should stay, as in adate +%Yformat. - cron uses the time zone of the computer it runs on, or the one that
CRON_TZnames in the crontab. The next runs on this page are in your browser's time zone. - Every line needs a newline at its end, the last one too: without it, cron takes the crontab as at least partly broken and writes a warning to syslog.
- When the clock moves forward by less than three hours, as it does for summer time, cron runs a job set for a time in the skipped hour right after the change; when the clock moves back, it does not run such a job twice. This applies to jobs set for a specific time and to jobs that run less often than once an hour; jobs that run more often follow the clock. That is how cronie's cron(8) describes it; its crontab(5) says instead that such jobs are skipped or run twice.
Sources
- Fields, values, names, ranges, lists, steps, random values, nicknames,
CRON_TZ, % in the command and the day rule, comments and the newline at the end: cronie's crontab(5); clock changes: cronie's cron(8) and crontab(5). Both at cronie 1.7.2.
More Linux tools
-
Exit code, signal and errno lookup
Look up 137, 139, 143 or any other exit code, a signal such as SIGKILL, or an errno value such as 111.
-
curl error code lookup
Read curl: (6), (7), (28), (35), (60) or any other curl error, with libcurl's name and what to check.
-
OpenSSL verify errors and command builder
Read verify error:num=20 and the others in plain words, and build openssl commands for PFX, PEM and CSRs.
-
chmod and umask calculator
Turn 755 into rwxr-xr-x and back, build a chmod command, and see what a umask leaves on new files.