Cron expressions provide a compact way to schedule recurring cloud and server tasks. This practical guide explains how to read the five fields, choose reliable schedules, account for time zones and daylight-saving changes, test expressions, and troubleshoot jobs that run at the wrong time—or not at all.
Overview
A cron expression is a pattern that tells a scheduler when a task may run. Traditional Unix-style cron uses five fields in this order:
minute hour day-of-month month day-of-week
| Field | Typical values | Useful symbols | Example |
|---|---|---|---|
| Minute | 0–59 | *, -, ,, / | 15 |
| Hour | 0–23 | *, -, ,, / | 2 |
| Day of month | 1–31 | *, -, ,, / | * |
| Month | 1–12 | *, -, ,, / | * |
| Day of week | 0–7, depending on the scheduler | *, -, ,, / | 1-5 |
The main symbols are straightforward:
*means every permitted value.,lists specific values, such as1,15.-defines a range, such as1-5./defines an interval, such as*/15for every 15 units within that field.
For example, 30 2 * * * means 02:30 every day under a five-field interpretation. 0 9 * * 1-5 means 09:00 on weekdays. Always confirm the scheduler’s documented syntax before copying an expression: some cloud services add a seconds field, use a question-mark placeholder, accept named months or weekdays, or require a separate timezone setting.
A cron expression controls timing, not reliability by itself. A production schedule also needs a clear timezone, an idempotent task, useful logs, failure notification, a timeout, and a policy for overlapping runs. For infrastructure-heavy workflows, pair the schedule with change controls and drift checks; the Terraform and OpenTofu drift detection workflow provides related guidance for safe reconciliation.
Checklist by scenario
Nightly backups
Start with a schedule that is easy to audit, such as 0 2 * * * for 02:00 daily in a five-field system. Before using it, check:
- The selected time does not compete with maintenance, ingestion, or reporting workloads.
- The job records its start time, end time, result, and backup location.
- Repeated execution is safe if a retry or manual rerun occurs.
- Retention and restore testing are handled separately from the schedule.
- The scheduler timezone is documented alongside the expression.
Reports and data pipelines
For a weekday report at 08:00, a common five-field pattern is 0 8 * * 1-5. Treat this as a starting point rather than proof that the report will contain the expected data. Confirm that upstream loads finish before the report begins, and decide what should happen when a source is late or incomplete.
For hourly processing, 10 * * * * runs at ten minutes past each hour. The offset can reduce contention with other jobs that all start at the top of the hour. If the task processes a time window, define that window explicitly and store a checkpoint so a delayed run does not silently skip data.
Cleanup and maintenance
A weekly cleanup at 03:30 on Sunday can be represented as 30 3 * * 0 in systems where zero represents Sunday. Because weekday numbering varies, verify the result with a cron builder or the target platform before deployment. Safer cleanup automation should include:
- A retention rule based on age, status, or an explicit allowlist.
- A dry-run or report mode for the first execution.
- Protection for active, recently modified, or legally retained data.
- Metrics showing how many objects were examined, retained, and removed.
Deployments and recurring operations
Scheduled deployments deserve more caution than routine housekeeping. If a release must occur at 22:00 on the first day of each month, an expression such as 0 22 1 * * may express the timing in a standard five-field environment. Add an approval step, a versioned configuration, a rollback plan, and an alert if the task starts but does not complete. For recurring operational work, distinguish between the trigger and the action so the action can be run manually without editing the schedule.
Using a cron builder or tester
A browser-based cron builder can help translate plain language into fields and show upcoming run times. Use it as a verification aid, not as a substitute for platform documentation. Enter the exact expression, select the intended timezone if supported, inspect several future occurrences, and then test the expression in a non-production target. Keep the final expression in version control with the job definition.
What to double-check
Timezone and daylight-saving behavior
Never assume that the scheduler uses the timezone displayed on your laptop. A service may default to UTC, a host may use its local timezone, or a scheduler may require an explicit timezone property. Write the timezone next to the expression in documentation and configuration.
Daylight-saving transitions create two distinct risks. A local time may occur twice when clocks move backward, or it may not occur when clocks move forward. Determine whether the platform skips, repeats, shifts, or rejects the affected run. For business-critical tasks, UTC can simplify scheduling, while a local timezone may be appropriate when the job is tied to business hours. Either choice should be deliberate and tested.
Field count and special syntax
Count the fields before deploying. A five-field expression pasted into a scheduler that expects seconds can shift every value into the wrong position. Also check whether the platform supports features such as ?, L, W, named weekdays, or an explicit timezone declaration. These features are not portable across all cron implementations.
Overlapping and missed runs
Ask what happens if one execution lasts longer than the interval. The scheduler may launch a second copy, queue the run, skip it, or leave the behavior to the application. Add a lock, concurrency limit, or idempotency key where duplicate work could cause damage. Define whether a missed run should be replayed, ignored, or reported for manual recovery.
Permissions, secrets, and observability
Confirm that the scheduled identity has only the permissions required for the task and that credentials are supplied through the platform’s approved secret mechanism. Avoid placing tokens directly in a cron line, which can expose them through configuration or process inspection. Capture structured logs and alert on failures, unusual duration, and expected output that did not arrive. For related secret-handling practices, see the cloud-native secrets management guide.
Common mistakes
- Reading fields as a sentence: Parse from left to right and label each field before interpreting the schedule.
- Using local time without documenting it: Write the timezone in the job definition, runbook, and alert description.
- Assuming every month has the requested day: A schedule for the 31st may not run in shorter months. Use a platform feature designed for month-end behavior or create an explicit workflow.
- Testing only the expression: A valid pattern can still invoke the wrong command, account, environment, or input window. Test the complete job.
- Starting every task at the same minute: Stagger independent jobs where shared resources are limited.
- Ignoring the scheduler’s result: A process can exit successfully while producing incomplete output. Validate the result, not only the exit code.
- Editing production schedules manually: Store schedules as reviewed configuration so changes are visible, reversible, and consistent across environments.
When to revisit
Review a cron schedule before seasonal planning cycles, especially when teams change business hours, reporting deadlines, or maintenance windows. Recheck it after a cloud migration, scheduler replacement, operating-system change, timezone policy change, or redesign of an upstream pipeline. A syntax that worked in one scheduler may not be portable to another.
Use this short audit before each significant change:
- Write the intended schedule in plain language, including timezone.
- Confirm the target scheduler’s field count, day-of-week numbering, and special syntax.
- Generate several upcoming run times with a cron builder or platform tester.
- Check dependencies, permissions, secrets, timeout, retries, and overlap behavior.
- Run the task safely in a test environment or dry-run mode.
- Deploy through reviewed configuration and verify the first production execution.
- Record the owner, purpose, expression, timezone, and recovery procedure.
For a deeper platform-specific reference, compare this checklist with Cron Jobs in the Cloud: Expression Syntax, Time Zones, DST, and Reliable Scheduling. Revisit both the expression and the surrounding workflow whenever the underlying tools or operational assumptions change.