This cron expression guide explains how to write, verify, and safely deploy recurring schedules. Use the field reference, scenario checklists, troubleshooting table, and pre-deployment checks whenever you create a cron job, configure a CI/CD scheduler, or migrate automation between platforms.
Overview
A cron expression is a compact schedule made from fields that describe when a command or workflow should run. The traditional Unix-style format has five fields:
minute hour day-of-month month day-of-week
For example, 30 2 * * * means “at 02:30 every day” in the scheduler's configured time zone. The expression alone does not tell you whether the job will finish successfully, whether a platform will retry it, or which time zone applies. Verification therefore requires both syntax checking and operational review.
Field-by-field cron syntax
| Field | Typical range | Purpose | Example |
|---|---|---|---|
| Minute | 0–59 | Minute within the hour | 15 |
| Hour | 0–23 | Hour in 24-hour time | 6 |
| Day of month | 1–31 | Calendar day | 1 |
| Month | 1–12, sometimes names | Month of the year | 1,4,7,10 |
| Day of week | Usually 0–7 | Day of the week | 1-5 |
Common operators include an asterisk for every permitted value, a comma for a list, a hyphen for a range, and a slash for a step. Thus, */15 means every 15 units, 1-5 means a range, and 1,15 means two specific values. Many cron implementations accept both 0 and 7 for Sunday, but this is not universal across all schedulers.
Some hosted automation tools and cron-like libraries add a seconds field, special tokens, or a different syntax altogether. Confirm whether the scheduler expects five fields, six fields, or a platform-specific format before copying an expression. A CI/CD pipeline design checklist can help place scheduled workflows alongside their trigger, approval, and failure-handling rules.
Checklist by scenario
For a daily job
- Choose the intended local or UTC time explicitly.
- Use five fields unless the target platform documents another format.
- Prefer a clearly named expression such as
0 1 * * *for 01:00 daily. - Confirm that the job is idempotent or protected against overlapping runs.
- Test the next several run times in a cron expression builder or scheduler preview.
For a weekday or weekly job
- Specify the day of week directly, such as
0 9 * * 1-5for 09:00 on weekdays. - Check how the target handles Sunday values and weekday names.
- Decide whether “weekday” means Monday through Friday in the platform's documented convention.
- Verify behavior during holidays separately; cron schedules normally represent calendar rules, not business calendars.
For monthly or quarterly work
- Account for months with fewer than 31 days. A schedule such as
0 3 31 * *will not run in shorter months on typical cron implementations. - Use a first-day schedule, such as
0 3 1 * *, when the requirement is “the first day of every month.” - For “last day of month” or “last weekday” logic, check whether the platform supports a special token. If not, use a wrapper script that calculates the date.
- For quarterly work, list the intended months explicitly, for example
0 4 1 1,4,7,10 *.
For CI/CD and hosted schedulers
- Read the platform's scheduler documentation rather than assuming Unix cron compatibility.
- Check whether schedules run in UTC, a project time zone, an account time zone, or a runner's local time.
- Confirm whether missed runs are skipped, queued, replayed, or triggered after a platform outage.
- Prevent duplicate deployments with concurrency controls, locks, or an idempotent deployment design.
- Keep credentials and tokens in the platform's secret store, not in the expression or command line.
For scheduled deployments, pair the expression with health checks and a rollback plan. The Kubernetes deployment guide covers rollout verification, while the progressive delivery checklist provides a useful review model for safer releases.
What to double-check
Day-of-month and day-of-week behavior is one of the most frequent sources of confusion. In many traditional cron implementations, when both fields contain restricted values rather than an asterisk, the job runs when either field matches. For example, 0 8 1 * 1 may run at 08:00 on the first day of the month and on Mondays, not only when the first day is a Monday. Some schedulers use different rules, so verify the target implementation.
| Symptom | Likely cause | What to check |
|---|---|---|
| Runs on the wrong weekday | Sunday numbering or platform-specific names | Whether Sunday is 0, 7, or another value; test a preview. |
| Runs twice or unexpectedly | Day-of-month/day-of-week matching rules or duplicate scheduler definitions | Implementation semantics and all active schedules. |
| Misses a run during clock changes | Daylight-saving transition | Time-zone policy, skipped times, repeated times, and platform handling. |
| Runs at a surprising hour | UTC versus local time | Scheduler, runner, container, and application time zones. |
| Monthly job does not run | Requested day does not exist in that month | Whether the schedule needs a wrapper script or first-day design. |
Daylight-saving time needs explicit treatment. A local time may occur twice, or it may not occur at all, during a clock transition. For jobs where timing must be predictable, UTC is often easier to reason about, provided the team accepts UTC as the business reference. If the schedule must follow a local business time, document the expected behavior and test transition dates before deployment.
Also review the command itself. Use an absolute executable path where appropriate, define required environment variables, set a working directory, capture standard output and errors, and make failures visible. For cloud jobs, confirm the identity has only the permissions it needs; the cloud IAM access review runbook is relevant when scheduled automation uses long-lived permissions.
Common mistakes
- Using six fields in a five-field scheduler: A seconds field is not automatically supported. Count the fields and consult the target documentation.
- Assuming “every five minutes” means an even wall-clock interval:
*/5 * * * *runs at minutes 0, 5, 10, and so on within each hour. It is not a five-minute delay measured from the previous completion. - Ignoring overlap: A job that takes longer than its interval can create concurrent runs. Add a lock, queue, concurrency limit, or idempotency guard.
- Relying on email alone: Configure logs, exit-status monitoring, and an alert path that the team actually reviews.
- Embedding secrets in commands: Use a managed secret or identity mechanism and avoid exposing credentials in process listings and logs.
- Testing only the expression: A valid expression can still invoke a missing binary, fail because of a minimal environment, or lack network access.
- Changing schedules without ownership: Record the purpose, owner, time zone, expected duration, retry policy, and safe-disable procedure.
When to revisit
Revisit a cron schedule before seasonal planning cycles, after a time-zone or infrastructure change, and whenever a workflow moves between servers, containers, CI/CD tools, or cloud platforms. A migration can change field count, supported special characters, time-zone defaults, retry behavior, and day-of-week semantics even when the expression looks unchanged.
Use this practical pre-deployment checklist:
- Write the requirement in plain language, including time zone and calendar rules.
- Identify the exact scheduler implementation and its supported syntax.
- Generate the next several run times with a trusted preview or cron expression builder.
- Test edge cases: month boundaries, daylight-saving transitions, Sunday handling, and missed runs.
- Confirm permissions, secrets, environment variables, paths, logs, alerts, retries, and concurrency behavior.
- Run the command manually in an environment that resembles production.
- Document the owner and review the schedule after any workflow or tool change.
Keep the expression beside the job definition and treat it as operational configuration, not an unexplained string. For broader automation troubleshooting, see the CI/CD pipeline failure troubleshooting guide. A short review before activation is usually cheaper than diagnosing a missed backup, duplicate deployment, or job that ran in the wrong time zone.