A reliable cron schedule is more than a row of numbers: it is a small automation contract that must be understood by both people and the system running it. This guide explains cron syntax, provides reusable schedule examples, and gives you a practical checklist for handling time zones, daylight-saving changes, missed runs, and differences between operating systems and cloud schedulers.
Overview
Cron is a compact notation for recurring tasks. A traditional Unix-style cron entry has five time fields followed by the command:
minute hour day-of-month month day-of-week command
For example:
30 2 * * * /opt/scripts/nightly-report.sh
In a standard five-field interpretation, this means “run at 02:30 every day.” The asterisk means every permitted value. A schedule can also use lists, ranges, and steps:
- List:
1,15,30selects specific values. - Range:
9-17selects a continuous interval. - Step:
*/10means every ten permitted units;1-30/5means every five units within that range. - Question of interpretation: names such as
MONorJANmay be accepted by some implementations, but numeric values and accepted ranges vary. Confirm the scheduler’s syntax before deployment.
Use a cron expression generator or browser-based cron builder to draft a schedule, but do not treat the generated expression as self-explanatory. Always read it back in plain language, test it against representative dates, and document the intended time zone.
| Field | Typical values | Meaning |
|---|---|---|
| Minute | 0-59 | Minute within the hour |
| Hour | 0-23 | Hour of the day in the scheduler’s time zone |
| Day of month | 1-31 | Calendar day, subject to the selected month |
| Month | 1-12 | Month of the year |
| Day of week | 0-7 or names | Weekday; the exact numbering convention must be checked |
Many cloud schedulers use a six-field form that includes seconds, while others use a six-field form that includes a year. Quartz-style expressions may also use a question mark in either the day-of-month or day-of-week position. These are not interchangeable with a five-field Unix expression. The scheduler’s documentation and validation rules are part of the schedule itself.
Checklist by scenario
To run a task at a regular interval
- Write the requirement in plain language, such as “every 15 minutes, all day.”
- Choose the correct field count for the target system.
- Build the expression, for example
*/15 * * * *for a typical five-field cron. - Confirm whether the task may overlap with a previous run.
- Add logging, an exit-status check, and an alert path before relying on the schedule.
To run a task at a particular local time
- Name the intended time zone explicitly, such as “09:00 Europe/Berlin,” rather than only writing “09:00.”
- Find out whether the host, container, or cloud scheduler uses UTC or a configured regional time zone.
- Check how the service handles daylight-saving transitions.
- Schedule a harmless test command and inspect its recorded timestamp.
- Document the time zone beside the expression in infrastructure code or runbook documentation.
Useful schedule templates
These examples assume a conventional five-field cron implementation:
0 * * * *— at the start of every hour.0 6 * * 1-5— at 06:00 on weekdays, subject to day-of-week numbering rules.15 9 1 * *— at 09:15 on the first day of each month.0 0 * * 0— at midnight on a selected Sunday-like weekday value; verify whether the target accepts 0, 7, or a named day.*/5 8-17 * * 1-5— every five minutes during the selected working-hour range on weekdays.
If you need “the last day of the month,” “the fifth weekday,” or a calendar rule that depends on holidays, plain cron may be the wrong abstraction. Use a scheduler with calendar-aware features, or trigger a daily job that performs an explicit date check in application code.
To troubleshoot a task that runs at the wrong time
- Copy the exact deployed expression, not the expression from a local draft.
- Record the scheduler’s time zone, host time, and observed execution time.
- Test each field independently: minute, hour, date, month, and weekday.
- Check whether the command is being run by the expected user and environment.
- Separate scheduling failure from application failure by invoking a minimal command that writes a timestamp to a known log.
What to double-check
Day-of-month and day-of-week behavior: Traditional cron implementations often treat these two fields differently from systems that require both to match. In some Unix cron variants, when both fields are restricted, a run can occur when either the day-of-month or day-of-week condition matches. Other schedulers use an AND interpretation or provide special syntax. Test this case rather than assuming.
Time zones: A cron expression has no universal time zone by itself. The effective zone may come from the operating system, a per-job setting, a container image, an environment variable, or the cloud scheduler configuration. “Midnight” is incomplete until the zone is known.
Daylight saving time: During a spring transition, a local clock time may not occur. During an autumn transition, a local time may occur twice. Scheduler behavior can include skipping, repeating, or normalizing a run. For critical workflows, decide whether the business rule is based on local time or elapsed UTC time, then verify the service’s documented behavior.
Missed runs: Traditional cron commonly does not replay every execution missed while a machine was powered off. Cloud schedulers may offer retry, catch-up, or delivery semantics, but these settings differ. Decide whether a missed run should be ignored, run once after recovery, or reconstructed from a time window.
Execution limits and overlap: A schedule may fire again while the previous invocation is still running. Use a lock, idempotency key, queue, or single-flight mechanism where duplicate processing would be harmful. Also check command timeouts, retry policies, concurrency limits, and maximum schedule frequency.
Environment: Cron often runs with a smaller PATH and fewer environment variables than an interactive shell. Use absolute executable paths, set required variables deliberately, quote arguments, and send standard output and errors to a controlled log.
Common mistakes
- Confusing fields: In
0 2 * * *, the first value is the minute and the second is the hour. Read from left to right and label each field while editing. - Assuming every scheduler uses five fields: Seconds, year fields, question marks, and special tokens can make a valid expression for one platform invalid on another.
- Using local time without recording it: A deployment to another region can silently change the observed schedule if the time zone is host-dependent.
- Ignoring the end of a range: “Every hour from 09:00 to 17:00” may or may not include 17:00 depending on the expression. List the expected fire times before publishing it.
- Putting complex shell logic directly in cron: Keep the cron entry short and call a version-controlled script with explicit error handling.
- Failing to make jobs idempotent: Retries, duplicate deliveries, manual reruns, and daylight-saving edge cases can all produce more than one invocation.
- Testing only the expression: A correct schedule can still fail because of permissions, network access, secrets, working directories, or an unavailable dependency.
A useful troubleshooting worksheet includes: the exact expression; scheduler and version; configured time zone; expected next three run times; observed run times; command or endpoint; execution identity; timeout; retry and overlap behavior; logs; and the result of a manual test.
When to revisit
Review a cron schedule before seasonal planning cycles, daylight-saving changes, a regional migration, an operating-system or container change, and any modification to the job’s runtime. Recheck it when a workflow moves from a server to a cloud scheduler, when a provider changes its cron syntax or limits, or when a task begins missing, duplicating, or drifting from its intended time.
For a practical review, start with the human requirement, generate or edit the expression, and compare the next several execution times with a calendar. Confirm the time zone and edge-case behavior in the target platform, run a safe test, and update the accompanying runbook. Store schedules as reviewed configuration where possible, with a comment that states the plain-language intent. Finally, monitor success, duration, and lateness so that a schedule failure is visible rather than discovered by the person waiting for its result.