Reliable scheduled automation starts with a schedule that is easy to read, portable enough for its target platform, and safe to run more than once. This cron expression guide explains how to build, review, and troubleshoot recurring jobs across Linux cron, Kubernetes CronJobs, and CI systems.
Overview
A cron expression is a compact description of when a job should run. In the traditional five-field format, the fields represent minute, hour, day of the month, month, and day of the week:
* * * * * command
- - - - -
| | | | |
| | | | +-- day of week (0-7, depending on the scheduler)
| | | +---- month (1-12)
| | +------ day of month (1-31)
| +-------- hour (0-23)
+---------- minute (0-59)
An asterisk means every permitted value. A comma lists separate values, a hyphen defines a range, and a slash defines an interval. For example, 0,30 means at minute zero and minute thirty, 1-5 means values one through five, and */15 means every fifteen units within that field.
The expression 15 2 * * * runs at 02:15 every day according to the scheduler's time zone. The command or job definition is separate from the schedule, so the same expression can trigger a shell command, a container, a Kubernetes workload, or a CI pipeline.
Before using a browser-based cron expression builder or another online developer utility, identify the scheduler that will execute the result. A valid Linux cron expression may need adjustment for Kubernetes or a CI provider. Treat a builder as a way to inspect and test an expression, not as a substitute for checking the platform's own documentation.
Checklist by scenario
1. Translate plain English into fields
- Write the requirement in a complete sentence, including the intended time zone. For example: “Run the backup at 02:15 every day in the database region's local time.”
- Choose the smallest schedule that expresses the requirement. Start with the minute and hour, then decide whether the job is restricted by date, month, or weekday.
- Fill in unspecified fields with an asterisk. A daily schedule at 02:15 becomes
15 2 * * *. - Check whether the job's duration could overlap with the next run. A schedule describes start times; it does not automatically prevent concurrent executions.
- Write down the expected next few run times and compare them with a cron expression builder or scheduler-specific test tool.
2. Common cron job examples
| Requirement | Expression | Interpretation |
|---|---|---|
| Every five minutes | */5 * * * * | At every five-minute interval |
| Daily backup at 02:15 | 15 2 * * * | At 02:15 every day |
| Hourly report at minute 10 | 10 * * * * | At ten minutes past every hour |
| Weekday cleanup at 23:30 | 30 23 * * 1-5 | At 23:30, Monday through Friday |
| Monthly task on the first day | 0 4 1 * * | At 04:00 on day one of each month |
| Quarterly task on the first day of selected months | 0 6 1 1,4,7,10 * | At 06:00 on the first day of January, April, July, and October |
These examples use the conventional five-field form. Day-of-week numbering can differ: some systems accept both zero and seven for Sunday, while others document names or a different range. Confirm the accepted values before deployment.
3. Backups and reports
For backups, schedule a time with predictable system and database load, then add operational safeguards outside the expression. The job should record a start time, completion status, and failure reason. It should also make its output identifiable so an operator can distinguish a new backup from a previous attempt.
For reports, decide whether “daily” means every calendar day or only business days. 0 7 * * 1-5 expresses weekdays at 07:00, but it does not know about holidays. If holidays matter, use a calendar-aware workflow or an explicit exclusion mechanism rather than trying to force the entire policy into a basic cron expression.
4. Cleanup and maintenance jobs
Cleanup jobs deserve a conservative schedule and a clear boundary. Instead of deleting everything matching a broad pattern, make the command select records or files older than a defined retention period. Use a dry-run mode where available, log the selected items, and consider a lock or concurrency control so two cleanup processes cannot remove the same data unexpectedly.
5. Kubernetes CronJobs
A Kubernetes CronJob places the schedule in a workload manifest. A minimal example is:
apiVersion: batch/v1
kind: CronJob
metadata:
name: nightly-backup
spec:
schedule: '15 2 * * *'
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
containers:
- name: backup
image: example/backup:stable
Before applying a Kubernetes CronJob schedule, check the cluster version and the fields supported by that environment. Decide how missed runs, failed Jobs, retained history, and overlapping executions should be handled. A schedule alone does not define those behaviors. If the cluster supports an explicit time-zone setting, use it when the business requirement is tied to a named zone; otherwise, document the assumed scheduler time zone and test it.
6. CI schedules
CI systems commonly accept cron-like syntax, but the surrounding configuration varies. The schedule may live in a repository file, a project setting, or a pipeline definition. Confirm whether the system interprets the expression in UTC, a project time zone, or a runner-specific zone. Also check whether scheduled pipelines run from the default branch, whether a commit is required, and how credentials are supplied. These are platform behaviors, not properties of the five cron fields.
What to double-check
Time zones and daylight saving time
“02:00 every day” is incomplete without a time zone. Record the intended zone next to the expression and in the job's runbook. UTC is often easier to reason about for infrastructure tasks, while local time may be required for business reports.
Daylight-saving transitions can create a missing local time or a repeated local time. During the transition, a scheduler may skip, repeat, or otherwise handle a run according to its implementation. For high-impact jobs, test the behavior in a staging environment or use a scheduler with explicit time-zone and misfire semantics. For monthly and seasonal planning, review the next run dates rather than trusting a mental calculation.
Day-of-month and day-of-week interactions
When both day-of-month and day-of-week contain restrictions, traditional cron implementations may treat them as an either/or match rather than requiring both conditions. This is a frequent source of surprises. If you mean “the first weekday of the month,” do not assume that combining 1 in the day-of-month field with 1-5 in the weekday field expresses that meaning. Use a calendar-aware command, a wrapper script, or a scheduler feature designed for that rule.
Execution safety
- Make jobs idempotent where practical, so a retry does not duplicate data or produce an invalid state.
- Set timeouts and resource limits appropriate to the workload.
- Prevent overlapping runs with a lock, a platform concurrency policy, or an application-level mechanism.
- Capture logs and alert on failure, not just on the absence of expected output.
- Keep credentials in the platform's secret mechanism rather than embedding them in a command or manifest.
For related operational checks, see the cloud cost estimation workflow before introducing frequent scheduled workloads, and review secret scanning practices before committing scheduler configuration.
Common mistakes
- Confusing fields:
0 0means midnight, not noon. Read the fields from left to right and label them before editing. - Assuming an expression is universal: Extended formats may include seconds or a year, while other platforms accept only five fields. Verify the target scheduler.
- Ignoring the environment: A scheduled shell command may run with a different working directory, PATH, user, or network access than an interactive session.
- Using a local time without recording it: A later migration to a container platform or CI runner can silently change the effective time zone.
- Scheduling expensive work too frequently: Estimate runtime, storage, network, and database impact before choosing an interval.
- Testing only the expression: A correct schedule can still trigger a broken command, an expired credential, or a container that cannot start.
- Relying on comments as controls: If a job must not overlap or must skip a holiday, encode that behavior in the workflow rather than documenting it only in prose.
When a schedule is difficult to express, split the responsibility: let cron start a small, observable controller and let application logic handle calendars, exclusions, retries, and business rules. That approach is often easier to test than an increasingly complex expression.
When to revisit
Revisit every cron expression when the workflow, platform, or calendar assumption changes. This includes moving a job from a server to Kubernetes, changing CI providers, relocating a database, changing the business reporting zone, or introducing a new retention policy.
Before seasonal planning cycles, inspect schedules that run near local midnight, month boundaries, daylight-saving transitions, and year-end holidays. Generate the next several run times in the target environment and verify that they match the operational requirement. After deployment, review actual run history for delays, overlaps, missed executions, and unexpected time-zone behavior.
Use this final checklist before acting:
- Identify the scheduler and its supported cron format.
- Write the requirement in plain language with an explicit time zone.
- Label each field and calculate representative next run times.
- Check overlap, retries, missed runs, permissions, secrets, and resource impact.
- Test the command or container independently from the schedule.
- Document the owner, expected output, failure alert, and next review date.
A cron expression is only one part of reliable automation. Treat it as versioned configuration, pair it with observable job behavior, and recheck it whenever the surrounding cloud-native workflow changes.