A reliable cron schedule is more than a string of numbers: it must express the intended frequency, run in the correct timezone, behave predictably during calendar changes, and be documented well enough for someone else to operate. This guide explains cron syntax, provides reusable schedule examples, compares common execution environments, and gives you a checklist for building and testing recurring jobs.
Overview
Traditional cron uses five fields in this order:
minute hour day-of-month month day-of-week
| Field | Allowed values in common Unix cron | Meaning |
|---|---|---|
| Minute | 0–59 | Minute within the hour |
| Hour | 0–23 | Hour of the day, usually in local scheduler time |
| Day of month | 1–31 | Calendar day |
| Month | 1–12 or names such as Jan | Month of the year |
| Day of week | 0–7 or names such as Mon | Day of the week; Sunday is commonly 0 or 7 |
Each field accepts a few basic operators:
- Asterisk (
*): every permitted value, such as every hour. - Comma (
,): a list, such as1,15for the first and fifteenth day. - Hyphen (
-): a range, such as9-17. - Slash (
/): an interval within a range, such as*/15for every 15 units.
Common cron schedule examples include:
| Expression | Typical meaning |
|---|---|
* * * * * | Every minute |
*/15 * * * * | Every 15 minutes |
0 * * * * | At the start of every hour |
30 2 * * * | Every day at 02:30 |
0 9 * * 1-5 | Weekdays at 09:00 |
0 0 1 * * | On the first day of each month at midnight |
0 3 * * 0 | Every Sunday at 03:00 in systems using 0 for Sunday |
These expressions describe a schedule, not the job itself. A production-ready entry also needs an explicit command or container, a known working directory, required environment variables, logging, a timeout strategy, and a way to prevent overlapping runs when a job can last longer than its interval.
Checklist by scenario
Writing a schedule for Linux or Unix cron
- Write the requirement in plain language. For example, “run the report at 06:15 every weekday in the operations timezone.”
- Translate one field at a time. That requirement becomes
15 6 * * 1-5in a five-field expression. - Check the scheduler’s timezone. The host timezone, container timezone, and your personal timezone may differ.
- Use absolute paths. Cron often runs with a smaller environment and a different working directory than an interactive shell.
- Capture output deliberately. Send standard output and errors to an appropriate log destination, and avoid silently discarding failures until the job is proven reliable.
- Test the command separately. First run the exact command manually with the same user, permissions, configuration, and working directory.
Using a cron expression generator or builder
A cron expression generator can reduce typing errors, but treat its result as a draft rather than an authority. Select the scheduler dialect first, enter the intended timezone, and verify the next several execution times. Pay particular attention to phrases such as “every five minutes,” “at minute five,” and “on weekdays”; these do not always map to the same expression. Save the plain-language description beside the generated expression so the schedule remains understandable during an incident.
Creating a Kubernetes CronJob schedule
Kubernetes CronJobs commonly use the same five-field schedule shape:
apiVersion: batch/v1
kind: CronJob
metadata:
name: daily-report
spec:
schedule: "15 6 * * 1-5"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
containers:
- name: report
image: example/report:stable
Before applying a Kubernetes CronJob, validate the YAML and schema, then review the job’s resource requests, limits, service account, secrets, and restart behavior. The concurrencyPolicy should reflect the workload: Forbid can prevent overlap, while Replace and the default allowing concurrent runs have different operational consequences. Consult the Kubernetes version and documentation used by your cluster for timezone support and scheduler behavior. For related checks, see the YAML troubleshooting guide and the resource requests and limits guide.
Scheduling a cloud or CI/CD task
Cloud schedulers and CI platforms may use cron-like syntax but add their own timezone rules, field extensions, minimum intervals, retry behavior, or delivery semantics. Confirm whether the platform interprets the expression in UTC or permits a named timezone. Then check whether a missed execution is skipped, retried, queued, or delivered after a delay. A schedule that looks correct in a local cron tester may not have identical behavior in a managed service.
What to double-check
Timezone and daylight-saving changes
“02:30 every day” is not a complete operational requirement unless its timezone is known. During daylight-saving transitions, a local time may occur twice or not occur at all. Different schedulers handle those cases differently. If the job represents an elapsed interval rather than a human calendar event, UTC or an interval-based mechanism may be easier to reason about. If it represents a business event, name the intended IANA timezone where the platform supports it and document the expected transition behavior.
Day-of-month and day-of-week combinations
When both day-of-month and day-of-week are restricted, traditional cron implementations commonly treat the fields as an either/or condition rather than requiring both to match. For example, 0 9 1 * 1 may run at 09:00 on the first day of the month and on Mondays. Do not assume every scheduler uses precisely the same rule. Test the expression in the target environment, especially for schedules such as “the first Monday of the month,” which may require platform-specific syntax or a wrapper script.
Missed runs, retries, and overlap
Ask what happens if the host is down, the controller is unavailable, the job fails, or the previous run is still active. Cron itself is not a complete workflow-management system. Add idempotency where possible, define retry and alerting behavior, and make the job safe to run again after a partial failure. For database or deployment work, connect the schedule to an explicit rollback or recovery plan; the database migration checklist and Kubernetes rollout guide provide useful adjacent checks.
Next-run verification
Never validate a cron expression only by looking at its punctuation. Use a cron tester or builder to calculate upcoming times, then verify at least one real execution in a non-production environment. Check the host or platform logs, command exit status, produced artifact, notification path, and execution timezone.
Common mistakes
- Confusing fields:
0 5 * * *means 05:00, not every five hours. - Using six-field syntax in a five-field scheduler: Some tools include seconds, while traditional Unix cron does not. Confirm the dialect before copying an expression.
- Assuming names are universal: Month and weekday names, Sunday numbering, and special macros vary by implementation.
- Ignoring quoting: In YAML, shell commands, and CI configuration, quote expressions when characters such as asterisks could be interpreted by the surrounding format.
- Relying on interactive environment settings: Explicitly define paths, credentials, configuration locations, and working directories.
- Allowing silent failure: A schedule that triggers but produces no observable success or failure signal is difficult to operate.
- Creating duplicate schedules: Check for an older crontab entry, a Kubernetes CronJob, a CI trigger, or a cloud rule that performs the same task.
- Forgetting clock changes: Review schedules that run near midnight, during maintenance windows, or around daylight-saving transitions.
When to revisit
Revisit a cron schedule before seasonal planning cycles, timezone changes, infrastructure migrations, or any workflow change that affects runtime, permissions, inputs, or outputs. Review it when moving from host cron to Kubernetes, a cloud scheduler, or CI/CD because syntax and missed-run behavior may change. Also revisit schedules after an incident, a daylight-saving transition, a change in business hours, or the introduction of a second automation system.
Use this short operational checklist before approving a new or modified job:
- Write the desired behavior, timezone, owner, and acceptable delay in plain language.
- Confirm the target scheduler’s field count, operators, timezone, and special syntax.
- Generate or calculate the next execution times and compare them with the requirement.
- Run the command with production-like permissions and configuration.
- Define logging, alerting, timeout, retry, idempotency, and overlap behavior.
- Test one scheduled execution and record the observed timestamp and result.
- Document the expression beside the plain-language schedule, owner, platform, and review trigger.
That final documentation turns a fragile string into an operable developer utility. When the underlying workflow changes, repeat the checklist rather than assuming a familiar cron expression still means what it did before.