Cron Expression Generator: How It Works
A cron expression is five fields describing when a job should run. The syntax is compact and unforgiving, and a single misplaced asterisk is the difference between a job running monthly and running every minute of a particular day.
The five fields
* * * * * | | | | | | | | | +-- day of week (0-7, 0 and 7 both Sunday) | | | +----- month (1-12) | | +-------- day of month (1-31) | +----------- hour (0-23) +-------------- minute (0-59)
| Operator | Meaning | Example |
|---|---|---|
* | Every value | * * * * * — every minute |
, | A list | 0 9,17 * * * — 09:00 and 17:00 |
- | A range | 0 9-17 * * * — hourly, 09:00 to 17:00 |
/ | A step | */15 * * * * — every 15 minutes |
Common schedules
| Expression | Runs |
|---|---|
0 * * * * | Every hour, on the hour |
*/5 * * * * | Every five minutes |
0 3 * * * | Daily at 03:00 |
0 3 * * 1 | Mondays at 03:00 |
0 3 1 * * | First of the month at 03:00 |
30 8 * * 1-5 | Weekdays at 08:30 |
0 0 1 1 * | Once a year, 1 January |
The mistake everyone makes once
* 3 * * * does not mean 'at 3am'. The minute field is an asterisk, so it runs every minute during the 3am hour — sixty executions. The correct expression is 0 3 * * *. Any field left as * means 'every value of this field', and the leftmost fields are the ones that bite.
Day-of-month and day-of-week together
When both are restricted, most cron implementations treat them as OR, not AND. 0 0 13 * 5 runs on the 13th of every month and on every Friday — not only on Friday the 13th. Restricting both fields rarely does what people intend, so restrict one and filter inside the job if you need the intersection.
Timezones and DST
Cron uses the server's local time unless configured otherwise. If that timezone observes daylight saving, a job scheduled at 02:30 may run twice or not at all on transition days. Running scheduled work in UTC avoids the problem entirely, and is the standard recommendation for anything where a missed or duplicated run matters.
Practical habits
- Stagger jobs. Everything at
0 0 * * *means everything competing at midnight. Spread them across the hour. - Prevent overlap. Cron starts a new run regardless of whether the previous one finished. Use a lock file or
flockfor jobs that might run long. - Capture output. Unredirected output is mailed to the user or silently discarded. Redirect to a log file so failures are diagnosable.
- Use absolute paths. Cron runs with a minimal environment and a different
PATHthan your shell — the most common reason a job that works interactively fails on schedule.
Non-standard extensions
Some systems add a seconds field at the front, making six fields — Quartz and Spring do this, and pasting a five-field expression into them shifts every value. Others support shorthand such as @daily, @hourly and @reboot. Check which dialect your scheduler uses before copying an expression from elsewhere.