A cron expression is small, but a scheduling mistake can run a job too often, at the wrong local time, or not at all. This guide explains how to read and write cron syntax, test a schedule, account for time zones and daylight saving time, and troubleshoot recurring jobs across Linux, CI systems, and cloud schedulers.
Overview
Traditional Unix cron uses five time fields followed by a command:
minute hour day-of-month month day-of-week command
| Field | Allowed values | Examples |
|---|---|---|
| Minute | 0–59 | 0, 15, */10 |
| Hour | 0–23 | 8, 18, 9-17 |
| Day of month | 1–31 | 1, 15, 1-7 |
| Month | 1–12, sometimes names | 1, 6-8, JAN |
| Day of week | 0–7, with Sunday commonly 0 or 7 | 1-5, MON-FRI |
The main operators are straightforward:
- Asterisk (
*) means every permitted value. - Comma (
,) creates a list, such as1,15. - Hyphen (
-) creates a range, such as9-17. - Slash (
/) creates a step, such as*/15for every 15th minute.
For example, 30 2 * * * means “at 02:30 every day” in the scheduler's configured time zone. It does not automatically mean 02:30 in the time zone of the person who wrote it.
Be especially careful when both the day-of-month and day-of-week fields contain specific values. In many traditional cron implementations, a job runs when either field matches, rather than only when both match. Other schedulers may document different behavior. Treat this as an implementation detail to verify, not an assumption.
Checklist by scenario
Every few minutes or hours
- Write the desired interval in plain language first: “every 10 minutes,” for example.
- Convert it to a step expression such as
*/10 * * * *. - Confirm whether the platform permits that frequency. Some managed schedulers impose a minimum interval or accept a restricted syntax.
- Make the job safe to retry. A delayed or duplicated invocation should not corrupt data or create duplicate notifications.
Once per day
- Choose the intended hour and minute explicitly, such as
0 6 * * *for 06:00 daily. - Identify the scheduler's time zone. A server, container, CI runner, and cloud service may not use the same default.
- Record the time zone beside the expression in configuration or documentation.
- Check the job's timeout and expected runtime so it cannot overlap with the next invocation unexpectedly.
Business days or monthly work
- Use a range or named weekdays only if the target scheduler supports that notation.
- For “first weekday of the month,” do not assume a single portable cron expression exists. Traditional cron fields describe matching dates, not every calendar rule. A wrapper script or scheduler-specific feature may be clearer.
- For month-end work, account for months with different lengths. A day-of-month value of 31 will not match every month.
- Test several calendar boundaries, including a short month, a weekend, and a year transition.
CI or cloud scheduling
- Read the platform's schedule syntax and field count. Some systems add a seconds field; others use only the standard five fields.
- Check whether the schedule is evaluated in UTC or an explicitly selected time zone.
- Verify minimum intervals, supported operators, branch or environment filters, and whether disabled workflows still retain schedules.
- Confirm that a scheduled run has the permissions, secrets, network access, and source revision it needs.
A cron expression generator can help produce an initial schedule, but the generated expression still needs to be checked against the target platform. Use a tester that lets you inspect upcoming run times, then compare those results with the scheduler's own documentation or dry-run facilities.
What to double-check
Time zones and daylight saving time
Choose a policy before choosing an expression. If the job represents a global interval, UTC is often easier to reason about. If it represents a local business event, such as opening-time processing, use the platform's supported local time-zone configuration or calculate the schedule with a time-zone-aware system.
Daylight saving transitions can produce a local time that occurs twice or does not occur at all. A scheduler may skip, delay, or run twice in that situation. Check its documented behavior, then decide whether the job should tolerate that outcome. For billing, reports, and other important workflows, log the intended time zone and the actual execution timestamp.
Command and environment
Cron usually runs with a smaller environment than an interactive shell. Use absolute paths where practical, define required environment variables explicitly, and redirect output to a controlled log destination. A command that works in a terminal may fail under cron because its working directory, shell, PATH, credentials, or network assumptions differ.
15 4 * * * /usr/local/bin/node /srv/app/scripts/sync.js >> /var/log/app-sync.log 2>&1
Keep the scheduled command short by calling a versioned script. Put validation, locking, retries, and meaningful error messages in that script or in the job runner rather than hiding complex logic inside the expression.
Overlap and observability
Ask what happens if one run lasts longer than the interval. Use a lock, queue, or platform concurrency control when overlapping executions are unsafe. Record start time, end time, result, schedule identifier, and a correlation ID where possible. Alerts should distinguish a failed job from a job that never started.
For API-driven jobs, inspect request and response details when a schedule appears to work but produces incorrect results. The JSON Formatter and Validator Guide can help inspect structured payloads during that investigation.
Common mistakes
- Reversing fields:
0 9 * * 1-5is 09:00 on weekdays; it is not “every nine minutes.” Read fields from left to right and label them during review. - Confusing “every N” with “at minute N”:
5 * * * *runs at five minutes past every hour, while*/5 * * * *runs every five minutes. - Assuming local time: A schedule can be correct syntactically and still run at the wrong business hour because the host uses another time zone.
- Ignoring the day-field rule: Combining day-of-month and day-of-week constraints can produce more runs than expected on traditional cron.
- Testing only the expression: A correct schedule does not prove that credentials, paths, permissions, dependencies, and network access are correct.
- Using a browser-based tester with sensitive data: A cron expression is generally harmless, but do not paste secrets, tokens, internal hostnames, or command arguments into an untrusted tool.
- Failing to make jobs idempotent: Retries and duplicate triggers are normal possibilities in distributed automation. Store a run key or otherwise make repeated execution safe.
When to revisit
Review a cron schedule whenever its inputs change, not only when the expression changes. Revisit it before seasonal planning cycles, daylight saving transitions, a move between hosting providers, a CI migration, a server image update, or a change in the application's time-zone policy.
Use this short audit checklist:
- Read the expression aloud and write down several expected run times.
- Generate upcoming occurrences with a cron expression generator or platform test feature.
- Compare those occurrences with the scheduler's documented field order, time zone, and supported syntax.
- Run the command manually in an environment that resembles production.
- Test failure, retry, timeout, overlap, and daylight-saving scenarios.
- Confirm logs, alerts, ownership, and a safe way to disable or roll back the job.
Keep the expression, its plain-language meaning, time zone, owner, and last verification date together in version control. That small record turns a fragile recurring task into maintainable developer productivity automation—and gives the next person a reliable starting point when the workflow or scheduling platform changes.
