Cron Expressions Explained: Syntax, Examples, Mistakes
How the five cron fields work, how to read any schedule at a glance, the day-of-month trap, timezone behaviour, and why cron silently fails.
By Velloreth
The shape of a cron expression
A cron expression is five whitespace-separated fields that describe a repeating schedule:
┌───────────── minute (0-59)
│ ┌─────────── hour (0-23)
│ │ ┌───────── day of month (1-31)
│ │ │ ┌─────── month (1-12, or JAN-DEC)
│ │ │ │ ┌───── day of week (0-6, Sunday = 0, or SUN-SAT)
│ │ │ │ │
* * * * *
Every field is a set of values. The job runs when the current time matches all five sets — with one notorious exception covered below.
The fields read left to right from largest time unit to smallest, except that day-of-month sits before month while day-of-week sits after it. That ordering is a historical accident and there is no way to fix it now.
The five operators
| Operator | Meaning | Example |
|---|---|---|
* | every value | * in minute = every minute |
, | list | 0,30 = at :00 and :30 |
- | range | 9-17 = 9 through 17 |
/ | step | */15 = every 15th value |
| names | month/day names | MON-FRI, JAN, DEC |
These combine, which is where expressions become readable or unreadable.
0 9-17 * * MON-FRI — every hour on the hour, 9 a.m. through 5 p.m., Monday to Friday. This is “business hours” and it is worth memorising as a shape.
*/10 8-18 * * * — every ten minutes, 8 a.m. to 6:59 p.m., every day.
0 0 1 * * — midnight on the first of every month.
30 2 * * 0 — 2:30 a.m. every Sunday.
Note the subtlety in */10 8-18: the step applies within the range, so minutes are 0, 10, 20, 30, 40, 50 — and the hour range means the last run is 18:50, not 18:59.
The day-of-month / day-of-week trap
This is the single most important quirk in cron, and it is genuinely counter-intuitive.
When both day-of-month and day-of-week are restricted (neither is *), cron runs the job if EITHER matches. It is an OR, not an AND.
0 0 13 * 5
You might read this as “Friday the 13th.” It actually means every Friday AND every 13th of the month. That is roughly 60 runs a year instead of one or two.
If you genuinely need “Friday the 13th,” you have to handle the intersection inside the script — run daily at midnight and exit immediately unless both conditions hold:
[ "$(date +%d)" = "13" ] && [ "$(date +%u)" = "5" ] || exit 0
The inverse case matters just as much: if one of the two fields is *, the restriction applies normally. 0 0 * * 5 is every Friday, as you would expect, because day-of-month being * does not participate in the OR.
Practical rule: restrict only one of the two day fields. If you must restrict both, write the constraint in the script instead of the expression.
Common schedules, decoded
| Expression | Meaning |
|---|---|
* * * * * | every minute |
*/5 * * * * | every 5 minutes |
0 * * * * | every hour, on the hour |
0 0 * * * | daily at midnight |
30 3 * * * | daily at 3:30 a.m. |
0 9 * * MON-FRI | weekdays at 9 a.m. |
0 0 * * 0 | Sundays at midnight |
0 0 1 * * | first of the month at midnight |
0 0 1 1 * | January 1st at midnight |
0 */6 * * * | every 6 hours |
15 2 * * 1-5 | 2:15 a.m. weekdays |
The named shorthands cover the most common ones: @hourly, @daily (also @midnight), @weekly, @monthly, @yearly (also @annually), and @reboot for once at startup.
Editing a crontab safely
crontab -e # edit your user's crontab
crontab -l # list it
crontab -r # REMOVE the whole thing — no confirmation, no undo
crontab -r has destroyed more automation than any other command in this article. There is no --dry-run and no trash. Before you type it, run crontab -l > ~/crontab.backup.
A crontab file is not a shell script. Each line is either a comment (#), a variable assignment, or a schedule followed by a command. You can set variables at the top, and it is worth doing:
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=you@example.com
# Back up the database nightly at 2:15 a.m.
15 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
Note that cron’s % character is special — it becomes a newline unless escaped as \%. This bites anyone trying to use date +\%Y in a schedule line.
Why cron jobs fail silently
Cron runs your command with a minimal environment: a short PATH, no ~/.bashrc, no ~/.profile, none of the variables your interactive shell exports. A script that works perfectly when you test it can fail every single night in cron, and by default you will never know.
These are the causes, in order of how often they are the answer:
1. PATH is too short. Your terminal finds node at /home/you/.nvm/versions/node/v22/bin/node; cron’s PATH does not include it. Use absolute paths for every command.
2. Environment variables are missing. Your .bashrc exports an API key; cron never sources it. Define needed variables in the crontab itself or, better, at the top of the script.
3. No output target. Cron mails output to MAILTO, and if mail is not configured — which it is not on most containers — the output goes nowhere. Always redirect: >> /var/log/job.log 2>&1. The 2>&1 part is essential; without it you lose stderr, which is where the actual error is.
4. Working directory. Cron starts in the user’s home directory, not your project. cd explicitly or use absolute paths.
5. File permissions. The script must be executable, and the user’s crontab runs as that user with that user’s permissions.
6. The process was not running. On a laptop, cron does not fire while the machine is asleep, and it does not catch up afterwards. A missed run is simply skipped.
The PATH and environment issues are the same class of problem described in environment variables explained — the process environment is a snapshot, and cron’s snapshot is nearly empty. The log-and-alert habit belongs with incident response for solo developers, since a solo operator is the only one who will notice.
Timezones, DST, and the hour that happens twice
Cron interprets the schedule in the system timezone, which on servers is often UTC while the developer is thinking in local time. A job at 0 9 * * * on a UTC server runs at 9 a.m. UTC — which is 2:45 p.m. in Kathmandu, not 9 a.m.
Modern cron implementations support a CRON_TZ variable:
CRON_TZ=Asia/Kathmandu
0 9 * * * /usr/local/bin/report.sh
But be careful, because daylight saving makes wall-clock schedules ambiguous. In a DST-observing timezone:
- On the spring-forward day, jobs scheduled in the skipped hour do not run at all.
- On the fall-back day, jobs scheduled in the repeated hour run twice.
For anything where a double-run is harmful — billing, notifications, idempotency-sensitive jobs — schedule against UTC and convert inside the application, or make the job idempotent so a second run is harmless. Nepal does not observe DST, but if you deploy to a region that does, this matters.
When cron is the wrong tool
Cron is excellent for “run this on a fixed schedule on one machine.” It is poor at anything else.
You need retries or catch-up. Cron has no concept of “this run failed, try again” and no awareness that yesterday’s run never happened. If a job must run exactly once per day regardless of outages, cron cannot guarantee it.
You need sub-minute precision. One minute is the floor.
You need to know whether it worked. Cron reports nothing. You need external monitoring — a heartbeat, a dead-man’s-switch service that alerts when a job does not ping, or at minimum a log line and something watching it. A cron job nobody monitors is a job that is already broken and you just do not know yet.
You have more than one machine. Two servers with the same crontab means the job runs twice. This is why containerized deployments should not use in-container cron with replicas greater than one.
The modern alternatives, roughly:
- systemd timers — sub-minute schedules, dependency ordering, journald logging,
Persistent=truefor catch-up after downtime. The right upgrade on a Linux host. - Kubernetes CronJobs — for cluster workloads, with
concurrencyPolicyand job history. - Platform schedulers — Cloudflare Cron Triggers, GitHub Actions
schedule, Vercel Cron. Managed, logged, and no server to maintain.
GitHub Actions is a genuinely good default for a small project’s scheduled jobs, because the run log is the monitoring. If you are automating a repo already, automating boring work with shell scripts covers writing the job body itself, and cloud cost models is worth a look before you move a high-frequency job onto a metered platform.
A debugging checklist for a cron job that will not run
Work through this in order and you will find it:
- Does the command work with a minimal environment? Test it with
env -i /bin/bash -c '/path/to/script.sh'. If that fails, cron will fail the same way, and your terminal was hiding the problem. - Is the schedule actually matched? Paste the expression into a decoder rather than reasoning about it — five fields are easy to misalign.
- Is the job in the right crontab?
crontab -las your user;sudo crontab -lfor root;/etc/cron.d/and/etc/crontabare separate files with a different format that includes a user column. - Is cron itself running? In a container, usually not — nothing starts the daemon.
- Is there a log?
journalctl -u cronor/var/log/syslog, plus the job’s own redirected log. - Did the job run but fail? Check the log for the real error; an exit code alone tells you nothing useful.
- Is the machine awake? On a laptop, the answer is often no.
Step 1 catches the majority. Cron’s environment is the difference between the machine you are sitting at and the machine your job actually gets.
The short version
Five fields: minute, hour, day of month, month, day of week. * for any, , for a list, - for a range, / for a step. Restrict only one of the two day fields, because cron ORs them. Always redirect output to a log. Always use absolute paths. Always monitor that the job ran, because cron will never tell you it did not.
Everything else about cron follows from those.