A reliable cron job starts with more than a valid-looking string. This guide explains cron schedule syntax, shows practical expressions for common recurring jobs, and provides a reusable validation checklist for Linux cron, Quartz, Kubernetes, and managed cloud schedulers. Use it before deploying a job, changing its timing, or investigating a missed run.
Overview
A cron expression describes when a recurring task should run. In traditional Unix and Linux cron, the expression usually contains five fields: minute, hour, day of month, month, and day of week. Each field accepts a number, a range, a list, or a step value. The scheduler evaluates the expression using the host's configured time zone unless the platform provides a separate time-zone setting.
| Field | Linux cron range | Meaning | Example |
|---|---|---|---|
| Minute | 0–59 | Minute of the hour | 15 |
| Hour | 0–23 | Hour in 24-hour time | 6 |
| Day of month | 1–31 | Calendar day | 1 |
| Month | 1–12 | Calendar month | 1-6 |
| Day of week | 0–7 | Weekday; 0 and 7 commonly represent Sunday | 1-5 |
The asterisk means “every permitted value.” A slash creates a step, such as */15 for every 15 minutes within the hour. A comma creates a list, such as 1,15, and a hyphen creates a range, such as 9-17. A cron builder can help generate an expression, but you should still read the resulting fields and test the schedule in the target platform.
Syntax is not universal. Quartz commonly adds a seconds field and uses ? when either the day-of-month or day-of-week field is intentionally unspecified. Kubernetes CronJobs generally use a five-field cron format, while cloud schedulers may add their own time-zone controls, delivery behavior, retry settings, or expression formats. Always compare a generated expression with the documentation for the scheduler that will execute it.
Checklist by scenario
Hourly and interval schedules
- Every hour:
0 * * * *— runs at minute zero of every hour. - Every 15 minutes:
*/15 * * * *— runs at minutes 0, 15, 30, and 45 of each hour. - Every two hours at minute 20:
20 */2 * * *— runs at 00:20, 02:20, 04:20, and so on. - Every weekday during business hours:
0 9-17 * * 1-5— runs at the start of each selected hour, Monday through Friday.
Be precise about the phrase “every N minutes.” */20 means the minute field is divisible by 20 within each hour; it does not necessarily mean a rolling 20-minute interval from the moment the job was installed. If a job needs elapsed-time behavior, use a worker, queue, or scheduler feature designed for that purpose.
Weekday and daily schedules
- Every day at 02:30:
30 2 * * *. - Monday through Friday at 08:00:
0 8 * * 1-5. - Saturday and Sunday at 10:15:
15 10 * * 6,0.
Confirm how the target interprets weekday numbers. Some systems accept names such as MON-FRI, but numeric and named forms are not equally portable across every implementation.
Monthly schedules
- First day of every month at 01:00:
0 1 1 * *. - 15th day of every month at 18:30:
30 18 15 * *. - Quarterly on the first day of January, April, July, and October:
0 3 1 1,4,7,10 *.
A schedule for the 31st day does not automatically mean “the last day of the month.” Shorter months may skip the run. If the business rule is “last calendar day,” implement that logic inside the job or use a scheduler with an explicit last-day feature.
Kubernetes and Quartz schedules
For a Kubernetes CronJob, a familiar five-field expression such as 0 3 * * * expresses a daily 03:00 schedule, but the cluster's Kubernetes version and configuration determine available time-zone behavior and job controls. Review the CronJob documentation for the version you operate, then consider concurrency policy, starting deadlines, retries, and cleanup settings separately from the expression.
Quartz commonly uses a seconds field. A daily 03:00 expression may be written as 0 0 3 * * ?, where the first zero is seconds and ? leaves day-of-week unspecified. Do not copy a Quartz expression into Linux cron or Kubernetes without converting its field count and special characters.
What to double-check
- Field count and order: Count the fields and label them before saving the schedule. A valid-looking expression can still put an hour value in the minute position.
- Time zone: Identify whether the schedule uses server time, container time, UTC, or an explicit scheduler time zone. Record that choice next to the expression.
- Daylight saving changes: A local-time job near a clock transition may run twice, run once, or be skipped, depending on the scheduler. For billing, data processing, and notifications, define the desired behavior rather than assuming it.
- Missed runs: Determine what happens if the host is down, a container cannot start, or a previous run is still active. Cron syntax alone does not guarantee catch-up, retry, or single-instance behavior.
- Overlap: Estimate the job's maximum runtime. If it can exceed its interval, add a lock, queue, concurrency policy, or idempotency key so overlapping executions do not corrupt work.
- Command environment: Use absolute paths where appropriate, define required environment variables, and send output to a known log destination. Interactive shell settings are often absent from scheduled jobs.
- Permissions and secrets: Test the command as the scheduler's actual user. Avoid placing credentials directly in the expression or command line when a safer secret mechanism is available.
- Observed next runs: Use a cron builder or local test utility to list upcoming dates, then verify at least one upcoming time manually against the intended time zone.
Scheduling is part of a wider operational workflow. If the job calls an API, document its version expectations; the API compatibility guide can help structure that contract. If it performs database changes, pair the schedule with a migration and rollback plan rather than treating automation as a substitute for deployment control.
Common mistakes
Confusing “at” with “every”
0 6 * * * means once daily at 06:00, not every six hours. Every six hours at the top of the hour is 0 */6 * * * in a five-field format.
Assuming the command will run from the project directory
A scheduled process may start with a different working directory and a smaller environment than your terminal. Use an explicit working directory, absolute executable paths, and structured logging. Test a wrapper script if the command needs several setup steps.
Combining day-of-month and day-of-week without checking semantics
Traditional cron implementations can treat restricted day-of-month and day-of-week fields with an OR relationship rather than requiring both conditions. This varies by scheduler and is easy to misread. If both fields are constrained, verify the actual next-run dates instead of relying on intuition.
Using a monthly expression for a business calendar
“The last business day” and “the third working day after month end” are not ordinary fixed-date schedules. Trigger a more frequent job and let application logic calculate the business date, or use a scheduler with calendar support.
Ignoring duplicate delivery
Retries, restarts, and overlapping schedules can cause a task to execute more than once. Make important jobs idempotent: record a run key, use transactional boundaries, and make repeated requests safe where possible.
For related workflow debugging, a browser storage and cookie investigation can help when a scheduled browser-driven task appears to lose session state, while a database migration checklist is useful when automation changes schemas. Keep the scheduler's responsibility narrow and make dependencies observable.
When to revisit
Recheck a cron expression before each seasonal planning cycle, after a server or container moves time zones, and whenever the job's owner, command, dependency, or execution platform changes. Revisit it after migrating from Linux cron to Quartz, Kubernetes, or a cloud scheduler because field counts, special characters, time-zone controls, retries, and missed-run behavior may differ.
Keep a small schedule record with the expression, plain-English meaning, time zone, expected next-run examples, owner, and failure procedure. When changing the schedule, validate the old and new expressions side by side and monitor the first few executions. A practical final checklist is:
- Can another engineer explain every field?
- Does the expression match the platform's documented syntax?
- Is the intended time zone written down?
- Are daylight saving, downtime, retries, and overlaps addressed?
- Is the task idempotent and observable?
- Have upcoming run times been verified rather than guessed?
Use this checklist whenever you generate a cron expression, audit an existing job, or move automation between platforms. The expression is only one part of a dependable schedule; clear ownership, safe execution, and verified timing complete the workflow.