cron Expression Explainer: When Does This Actually Run?

Paste the five time fields from a crontab line. You get it in plain English, the next five runs, the mistakes that catch people out, and the same schedule as a systemd timer.

Your Schedule

Just the schedule, not the command. Macros such as @daily and @reboot work too.

At 02:30 on Monday to Friday.

The Next Five Runs

In your browser's time zone. The server runs cron in its own, often UTC.

As a systemd timer (in the .timer file's [Timer] section)
OnCalendar=Mon,Tue,Wed,Thu,Fri *-*-* 02:30:00

The Five Fields

FieldValuesExamples
Minute0–590 on the hour, */15 every 15 minutes, 5,35 twice an hour
Hour0–232 at 2am, 9-17 office hours, */6 every six hours
Day of the month1–311 the 1st, 1,15 twice a month
Month1–12 or JAN–DEC*/3 quarterly, JAN January only
Day of the week0–7 or SUN–SAT1-5 weekdays, 0 or 7 Sunday

Jobs That Fail Quietly

Nobody sees the errors. Cron mails output to the local user, which nobody reads. Send it to a log, and have something alert when the job stops running: a check-in to a monitoring service at the end of the script catches a job that has silently stopped.

Runs pile up. A job every five minutes that sometimes takes ten ends up with two copies fighting over the same files. flock -n stops that.

The clocks change. On a server set to UK time, a job between 01:00 and 02:00 runs twice in October and not at all in March. Keep servers on UTC.

It lives on one server. A crontab that exists only on the old server is forgotten in a migration. Keep schedules in the repository or in configuration management, with a note of what each one does.

Questions

What do the five fields in a cron schedule mean?

In order: minute (0 to 59), hour (0 to 23), day of the month (1 to 31), month (1 to 12 or JAN to DEC) and day of the week (0 to 7, where 0 and 7 are both Sunday, or SUN to SAT). 30 2 * * 1 runs at 02:30 every Monday.

What does */15 mean in cron?

Every 15th value of that field, counting from the start. In the minute field, */15 runs at :00, :15, :30 and :45. It restarts each hour, so */7 runs at :56 and then at :00, only four minutes later.

Why did my cron job run on the wrong day?

Usually because both the day of the month and the day of the week are set. Cron then runs when either matches, not both: 0 9 1 * 1 runs on the 1st of every month and on every Monday. To run only on the first Monday, set the day of the week in cron and check the date inside the script.

What time zone does cron use?

The server's own time zone, usually UTC on cloud servers. Check with timedatectl. A job at 01:30 on a server set to UK time runs twice, or not at all, on the nights the clocks change; scheduling in UTC avoids that.

Why does my cron job work by hand but not from cron?

Cron runs with a minimal environment: a short PATH, no shell profile and a different working directory. Use full paths to commands and files, set any variables the script needs at the top of the crontab, and send output to a log (>> /var/log/job.log 2>&1) so you can see the error.

How do I stop a cron job running twice at once?

Wrap the command in flock -n /tmp/job.lock. If the last run is still going, the new one exits straight away instead of starting a second copy.

Should I use cron or systemd timers?

Either works. systemd timers log every run to the journal, can catch up on runs missed while the server was off (Persistent=true), and show their next run in systemctl list-timers. The explainer gives the OnCalendar line for most schedules.

Scheduled Jobs You Can't Vouch For?

Backups, renewals, imports and clean-ups: I find every job on your servers, make sure each one is monitored, and write down what it does.