A cron expression turns a recurring schedule into a compact set of fields, but small differences in syntax, time zones, and platform behavior can produce surprising runs. This guide explains how to build, read, test, and safely deploy cron schedules, with practical examples and a reusable pre-deployment checklist.
Overview
A traditional cron expression has five fields, read from left to right:
minute hour day-of-month month day-of-week
| Field | Allowed values | Example |
|---|---|---|
| Minute | 0–59 | 30 |
| Hour | 0–23 | 8 |
| Day of month | 1–31 | 15 |
| Month | 1–12, sometimes names | 1 |
| Day of week | 0–7, sometimes names | 1 |
An asterisk means “any permitted value.” A comma creates a list, a hyphen creates a range, and a slash creates a step:
*— every value1,15— the first and fifteenth1-5— values one through five*/15— every 15 units, starting at the field’s minimum
For example, 30 8 * * 1-5 means 08:30 on weekdays in a five-field cron implementation. The expression describes when a job may start; it does not guarantee that the job will finish before the next scheduled start.
Use a cron expression generator or cron syntax checker as a review aid, not as a substitute for reading the scheduler’s documentation. The same-looking expression can behave differently across operating systems, CI services, container platforms, and cloud schedulers.
Checklist by scenario
Every few minutes
Use a step value in the minute field. To run every 10 minutes, start with:
*/10 * * * *
This generally runs at minutes 0, 10, 20, 30, 40, and 50 of each hour. If the requirement is “10 minutes after the job finishes,” cron is not the right mental model: cron uses scheduled clock times, while completion-based scheduling requires application logic or a scheduler with dependency support.
Once each day
Set a specific minute and hour, then leave the calendar fields open. For 02:15 every day:
15 2 * * *
Choose the hour deliberately. Overnight jobs are often affected by the server’s time zone, daylight-saving changes, maintenance windows, or a recent change in the host environment.
Weekdays only
Use a weekday range when the scheduler supports numeric weekday values in the expected format:
0 9 * * 1-5
This represents 09:00 from Monday through Friday in the common convention where Monday is 1 and Friday is 5. Some implementations accept weekday names, and some treat both 0 and 7 as Sunday. Confirm the convention before deploying.
Weekly or monthly maintenance
For a weekly Sunday run at 03:00, a common expression is:
0 3 * * 0
For the fifteenth day of every month at 01:30:
30 1 15 * *
Be precise about business language. “The last day of the month” is not represented consistently by basic cron syntax. A schedule such as day 31 will not run in shorter months, so use a wrapper script or a scheduler feature that explicitly supports end-of-month logic.
Business-hour intervals
To run every 20 minutes during hours 9 through 17, Monday through Friday, one possible expression is:
*/20 9-17 * * 1-5
Check whether the final hour should include 17:40. If the intended window ends at 17:00, split the schedule or use a guard in the command. A cron parser may validate the expression while still allowing a time outside the business window you intended.
Kubernetes and hosted automation
A Kubernetes CronJob normally uses the familiar five-field schedule format, but the surrounding YAML, concurrency policy, suspension behavior, missed-run handling, and time-zone support are platform concerns rather than parts of the expression itself. Validate the complete manifest, not only the value of spec.schedule.
GitHub Actions and other hosted CI systems also use cron-like schedules, but their default time zone, minimum interval, delays, and behavior during service interruptions are defined by the service. Cloud schedulers may add a dedicated time-zone setting or use a different field count. Always compare your expression with the target platform’s current documentation before relying on it for releases, billing, backups, or notifications.
What to double-check
- Time zone: Identify whether the schedule uses the host, container, account, project, workflow, or an explicitly configured time zone. Do not assume your local clock is the scheduler’s clock.
- Daylight-saving changes: A local time may occur twice, or not occur at all, when clocks change. Decide whether the job should run once, twice, or be skipped, and test the platform’s documented behavior.
- Day-of-month and day-of-week interaction: In many traditional cron implementations, restricting both fields can mean “either condition,” not “both conditions.” A schedule intended for a specific intersection may need a wrapper check or a platform-specific solution.
- Command environment: Cron often runs with a limited working directory, PATH, shell, and set of environment variables. Use absolute paths where appropriate and load configuration explicitly.
- Overlap: Confirm what happens if one run is still active when the next one starts. Add a lock, idempotency key, queue, or concurrency setting when duplicate work would be harmful.
- Failures and retries: Decide where logs go, how failures are reported, and whether a missed run should be retried or skipped. A valid expression does not provide monitoring by itself.
- Permissions and secrets: Test the job using the same identity and secret-loading method it will have in production. Avoid placing credentials directly in an expression or command line.
For sensitive inputs, keep debugging separate from secret exposure. The same principle used when inspecting tokens or encoded values applies here: validate structure and behavior without pasting credentials into an online tool or shared log. Related guidance is available in the JWT debugging guide and safe data transformation guide.
Common mistakes
- Confusing “every five hours” with “at five-hour intervals”:
0 */5 * * *runs at selected clock hours, not necessarily five hours after the previous execution. - Using six fields in a five-field scheduler: Some systems include seconds; traditional crontab syntax usually does not. Count the fields and check the target format.
- Assuming a slash means a calendar interval:
*/2in the month field means every other permitted month, not two months after the previous successful run. - Ignoring output: A job that runs silently can still fail. Capture standard output and errors, then connect them to an alert or review process.
- Testing only the parser: Syntax validation cannot reveal an incorrect time zone, missing permission, bad working directory, API outage, or overlapping execution.
- Scheduling destructive actions without a dry run: First test against a safe dataset, add clear logging, and make the command idempotent where possible.
If a schedule behaves unexpectedly, compare the intended plain-language rule with the actual expression field by field. Then inspect the scheduler’s recorded next-run time, execution time zone, logs, and exit status. A text diff can help when reviewing changes to deployment files or environment configuration; see the text diff workflow for a systematic comparison method.
When to revisit
Revisit a cron expression whenever the underlying schedule or execution environment changes. That includes seasonal planning cycles, daylight-saving transitions, a move between servers or cloud platforms, a change in container images, a new deployment region, or a change to the job’s runtime. Review it before recurring campaigns, reporting periods, backups, subscription processes, and other calendar-dependent workflows.
Use this final pre-deployment checklist:
- Write the requirement in plain language, including the intended time zone.
- Translate it into the scheduler’s documented field format.
- Run the expression through a cron expression generator or syntax checker.
- Inspect several upcoming run times, including a month boundary and any daylight-saving transition that matters.
- Test the command independently with production-like permissions and configuration.
- Define logging, alerts, retries, overlap protection, and missed-run behavior.
- Record the expression’s purpose beside the configuration so a future editor does not have to reverse-engineer it.
When a workflow changes, update both the expression and its written explanation. That small habit makes schedules easier to audit and gives you a reliable starting point the next time a job runs at the wrong hour—or does not run at all.