Cron Expression Guide: Build, Test, and Document Reliable Schedules
A cron expression is small, but its operational impact can be large. This guide explains how to write and verify recurring schedules, compare Linux, CI/CD, Kubernetes, and cloud-scheduler behavior, and document the timezone and failure assumptions that keep automation predictable.
Overview
Cron expressions describe when a recurring job should run. In the traditional five-field format, the fields represent minute, hour, day of the month, month, and day of the week:
| Field | Allowed values | Common symbols | Example |
|---|---|---|---|
| Minute | 0–59 | * , - / | 15 |
| Hour | 0–23 | * , - / | 2 |
| Day of month | 1–31 | * , - / | * |
| Month | 1–12, sometimes names | * , - / | * |
| Day of week | 0–7, depending on implementation | * , - / | 1–5 |
The expression 15 2 * * * means “at 02:15 every day,” assuming the scheduler uses the host or configured timezone. Asterisk means every permitted value. A comma lists values, a hyphen defines a range, and a slash defines an interval. For example, 0,30 means at minute zero and thirty, 9-17 means values from nine through seventeen, and */10 means every ten units within the field.
Start with the desired behavior in plain language before writing syntax. Specify the exact time, timezone, frequency, acceptable delay, and whether a missed run should be replayed. A cron expression generator or browser-based cron builder can help produce and inspect an expression, but it should support—not replace—testing in the scheduler that will run the job.
Checklist by scenario
Linux or Unix crontab
- Write the schedule in local terms. For example: “Every weekday at 06:30 in the server’s configured timezone.”
- Translate it to five fields. The expression for that example is
30 6 * * 1-5. - Confirm the account and environment. Cron may run with a smaller environment than an interactive shell. Use absolute paths, define required variables explicitly, and send output to a controlled log or monitoring destination.
- Make the command safe to repeat. A retry, duplicate trigger, or manual rerun should not corrupt data. Use locking or an idempotent job design where overlap is possible.
- Test the installed crontab. Validate both the expression and the command under the same user and host conditions used in production.
CI cron jobs
Continuous integration platforms commonly use cron-like schedules, but the configuration location and timezone behavior vary. Before committing a scheduled workflow:
- Check whether the platform interprets the schedule in UTC or another configured timezone.
- Confirm whether the scheduler runs on the default branch, a selected branch, or the workflow revision associated with the event.
- Check how manual runs, disabled workflows, queued jobs, and concurrent executions are handled.
- Use a narrow test schedule temporarily, then change it to the intended production cadence.
- Add a visible step that records the trigger time, commit or configuration revision, and target environment.
A schedule such as 0 4 * * 1 is often read as “04:00 every Monday,” but the actual local time depends on the CI provider’s timezone rules. Treat the platform documentation and a test run as the source of truth.
Kubernetes CronJob
A Kubernetes CronJob uses a cron-formatted schedule to create Jobs. A basic manifest might look like this:
apiVersion: batch/v1
kind: CronJob
metadata:
name: report-refresh
spec:
schedule: "15 2 * * *"
concurrencyPolicy: Forbid
startingDeadlineSeconds: 900
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: refresh
image: example/report-refresh:stableThe schedule alone is not enough to make a reliable Kubernetes workflow. Review the concurrency policy, retry behavior, starting deadline, history limits, resource requests, image version, permissions, and log retention. Choose a concurrency policy deliberately: allowing overlapping Jobs may be correct for independent work, while forbidding overlap is safer when two runs could modify the same records.
Check the Kubernetes version and scheduler documentation for timezone support before relying on a timezone-specific schedule. If the cluster or platform does not support an explicit timezone setting, design around its effective timezone rather than assuming the operator’s local time. Also remember that a CronJob creates a Job; it does not guarantee that the resulting workload completes successfully.
Cloud schedulers and managed automation
Managed schedulers may support five fields, six fields, calendar expressions, or a provider-specific format. Some include seconds; others do not. Before copying a Linux expression, verify the field count, allowed names, timezone configuration, daylight-saving behavior, and retry model. Then check whether a failed invocation is retried, duplicated, delayed, or sent to a dead-letter destination. These details affect whether the target operation must be idempotent.
What to double-check before deployment
Timezone and daylight saving time
Timezone ambiguity is one of the most common causes of surprising schedules. Document the timezone beside the expression, not only in a runbook. “02:00 daily” is incomplete without stating whether it means UTC, the host timezone, or a named regional timezone.
Daylight-saving transitions can create a skipped local time in one direction and a repeated local time in the other. Scheduler behavior differs: a platform may skip, run once, run twice, or normalize the time. If the job handles billing, backups, notifications, or other time-sensitive work, prefer UTC when that matches the business requirement. If local civil time is required, test transition dates and define what should happen during an ambiguous or nonexistent hour.
Day-of-month and day-of-week semantics
In many traditional cron implementations, when both day of month and day of week are restricted, a job runs when either field matches rather than only when both match. This is easy to misunderstand. For a “first weekday of the month” requirement, a plain expression may not express the intent reliably. Use a wrapper script that checks the date, a scheduler feature designed for calendar rules, or a tested application-level condition.
Day-of-week numbering also varies. Some implementations accept both seven and zero for Sunday, while others restrict names or numbers differently. Confirm the target scheduler’s accepted values instead of assuming that a Linux expression will transfer unchanged.
Missed runs, overlap, and observability
Ask three operational questions: What happens if the scheduler is unavailable? What happens if a run takes longer than its interval? What happens if the command fails after making a partial change? Configure locking, timeouts, retries, and alerting according to the job’s risk. Emit a start event, completion status, duration, and useful error context. A schedule is only reliable when operators can tell whether it ran and whether it achieved its purpose.
A practical verification workflow
- Write the schedule in plain language, including timezone and expected frequency.
- Break the expression into fields and explain each one.
- Generate the next several run times with a cron expression generator or the target platform’s preview feature.
- Check boundary cases: midnight, month-end, leap day, weekday transitions, and daylight-saving changes when relevant.
- Run the command manually with the production-like user, permissions, environment, and input data.
- Deploy first to a non-production target or use a temporary frequent schedule.
- Observe at least one successful run and one intentional failure path.
- Record the final expression, timezone, owner, expected duration, retry behavior, and rollback or replay procedure.
Common mistakes
- Confusing intervals with calendar schedules.
*/5in the minute field means minutes divisible by five within each hour; it is not necessarily “five minutes after the previous run.” - Forgetting the timezone. A schedule that works in a developer’s timezone may run at an unexpected hour in a container, CI runner, or cluster.
- Using six fields without checking support. A seconds field is valid in some schedulers but invalid or misinterpreted in others.
- Ignoring command context. Relative paths, missing environment variables, shell differences, and permissions often cause cron jobs to fail even when the expression is correct.
- Allowing overlapping work unintentionally. A slow job can still be triggered again unless concurrency is controlled.
- Assuming scheduled means successful. Track the created Job or process through completion and alert on failure.
- Changing a schedule without documenting the reason. Keep the expression near the deployment configuration and explain its business or operational purpose.
When to revisit
Revisit a cron expression before seasonal planning cycles, timezone changes, major platform upgrades, or changes to the job’s duration and dependencies. Audit it whenever a workflow moves from a server to CI, Kubernetes, or a managed cloud scheduler, because syntax and timezone defaults may change with the execution environment.
Use this short review checklist:
- Does the expression still match the business requirement?
- Is the timezone explicit and still appropriate?
- Have recent daylight-saving, month-end, or leap-year cases been tested?
- Can the job overlap, fail partially, or run twice safely?
- Are retries, missed runs, permissions, logs, and alerts still configured?
- Does the target scheduler still support the syntax and fields being used?
Finally, regenerate and inspect the next run times after every schedule change. Commit the expression with its plain-language explanation and an example of expected output. That small habit turns a fragile line of punctuation into an auditable part of a dependable cloud-native workflow.