Cron Expressions Explained: Syntax, Examples, and a Safe Scheduling Workflow
cronschedulingautomationDevOpsbackend

Cron Expressions Explained: Syntax, Examples, and a Safe Scheduling Workflow

PPrograma Space Editorial Team
2026-11-27
6 min read

Learn cron syntax, compare common schedules, account for timezones and DST, and test recurring jobs safely before deployment.

Cron expressions look small, but a misplaced field can run a job too often, at the wrong time, or not at all. This guide explains cron syntax, compares common schedule formats, and provides a repeatable checklist for writing, testing, deploying, and reviewing scheduled jobs safely.

Overview

A traditional Unix cron expression contains five time fields followed by a command:

minute hour day-of-month month day-of-week command
FieldAllowed valuesExamples
Minute0–590, 15, */10
Hour0–232, 14, 9-17
Day of month1–311, 15, 1-5
Month1–12 or names supported by the implementation1, 6-8, JAN
Day of weekUsually 0–7, with Sunday represented by 0 or 71-5, MON-FRI

The command is not part of the expression itself in every scheduler. For example, a hosted scheduler, CI system, container platform, or application library may accept only the time fields and run a separate command or task definition. Always check whether the target system expects five fields, six fields with seconds, or another format.

Basic cron operators are straightforward:

  • Asterisk (*): matches every permitted value, such as every hour.
  • Comma (,): lists individual values, such as 1,15 for the first and fifteenth day of a month.
  • Hyphen (-): defines a range, such as 9-17.
  • Slash (/): defines a step, such as */15 for every 15 minutes.

A useful mental model is to read each field from left to right and translate it into plain language before running the job. If you cannot explain the expression in one sentence, it needs another review.

Checklist by scenario

Common recurring schedules

These examples use standard five-field cron syntax. They are starting points, not universal commands; confirm the timezone and field format in the system where they will run.

GoalExpressionMeaning
Every minute* * * * *Run once per minute.
Every 15 minutes*/15 * * * *Run at minute 0, 15, 30, and 45 of each hour.
Every day at 02:000 2 * * *Run at 2:00 a.m. each day.
Weekdays at 09:3030 9 * * 1-5Run Monday through Friday at 9:30 a.m.
Every Monday at 06:000 6 * * 1Run weekly on the selected day of week.
First day of each month0 0 1 * *Run at midnight on day one of every month.
Several times daily0 8,12,18 * * *Run at 08:00, 12:00, and 18:00.

Writing a new expression

  1. Write the requirement in plain language. Include the intended timezone, frequency, and any business-day or month-end rule.
  2. Choose the smallest applicable unit. Start with minutes, then hours, days, months, and weekdays. Do not begin with a memorized expression.
  3. Fill unspecified fields deliberately. An asterisk means every value, not “ignore this field” in a vague sense.
  4. Confirm the day-of-month and day-of-week behavior. In many traditional cron implementations, using restrictions in both fields can match either condition rather than requiring both. Other schedulers may use different rules.
  5. Test several upcoming run times. Check ordinary dates, month boundaries, weekends, and any special dates relevant to the task.
  6. Deploy with observability. Record start time, completion status, duration, and failure details. A schedule without a useful failure signal is difficult to operate.

Using a cron expression generator or tester

A cron expression generator can help construct a schedule, while a cron expression tester can show the next matching times. Treat these tools as verification aids rather than authoritative interpreters. Select the target implementation first, paste the generated expression into a test environment, and compare the displayed times with your plain-language requirement.

What to double-check

Implementation differences

“Cron” is used for several related formats. Traditional Unix crontabs commonly use five time fields. Some schedulers add a seconds field, changing the position of every value. Quartz-style expressions commonly use additional fields and may require a question mark in either the day-of-month or day-of-week field. Cloud platforms and CI systems can add their own restrictions or use a scheduler-specific dialect.

Before copying an expression, identify the scheduler, its field count, supported names, special characters, and whether it accepts a command, a job identifier, or only a schedule. Do not assume that an expression valid in a local crontab is valid in a workflow platform.

Timezone and daylight-saving transitions

Determine which clock controls the job: the host, container, application, scheduler service, or an explicitly configured timezone. A schedule intended for a business location can drift if it silently uses UTC or a server's local timezone.

Daylight-saving transitions create two edge cases. A local time can be skipped when clocks move forward, or occur twice when clocks move backward. The scheduler may skip, repeat, delay, or otherwise handle that time according to its implementation. For important jobs, document the expected behavior and make the task idempotent so an accidental retry does not duplicate work.

Execution behavior

  • Check whether a new run can begin while the previous run is still active.
  • Decide whether overlapping runs should be blocked, queued, or allowed.
  • Use absolute paths and an explicit environment where traditional cron provides a limited shell context.
  • Capture standard output and errors somewhere operators can inspect.
  • Define what happens after a missed run, host restart, deployment, or temporary service outage.
  • Give the job the minimum credentials and database permissions it needs.

For containerized tasks, also verify the image, mounted volumes, network access, and exit status. The troubleshooting approach in Docker Container Troubleshooting can help when the schedule fires but the container exits unexpectedly.

Common mistakes

  • Confusing fields: 0 2 * * * means 2:00, not 0:02. Read the fields in their documented order.
  • Using */30 as “twice per day”: in the minute field, it means every 30 minutes. A twice-daily job needs explicit hours, such as 0 8,20 * * *.
  • Assuming month-end support: day 31 does not represent the last day of shorter months. Use a scheduler feature designed for month-end behavior or make the command calculate the date safely.
  • Ignoring duplicate execution: retries, overlapping runs, and daylight-saving behavior can cause the same logical work to start more than once. Design database updates and API calls to tolerate repetition where possible.
  • Testing only the expression: a correct schedule can still fail because of permissions, missing environment variables, an unavailable database, or an incorrect working directory.
  • Using a human timezone without documenting it: write the timezone next to the schedule and in the job's operational notes.
  • Choosing an unnecessarily frequent schedule: run the job as often as the business requirement needs, not simply as often as the scheduler allows.

If a scheduled task calls an API, test authentication, pagination, rate handling, and partial failure separately from the schedule. The checklist in REST API Pagination Patterns is useful for recurring jobs that process more than one page of results.

When to revisit

Review a cron expression whenever the job, infrastructure, or calendar assumptions change. A recurring review is especially valuable before seasonal planning cycles, fiscal or reporting periods, timezone-sensitive campaigns, and periods when staffing or support coverage changes.

Revisit the schedule after migrating from a server crontab to a container platform, CI workflow, cloud scheduler, or application library. The field format, default timezone, retry behavior, and missed-run policy may all change. Also review it when a command gains new dependencies, accesses a different database, or begins processing a larger volume of data.

Use this final deployment checklist:

  1. Write the intended schedule in plain language, including timezone.
  2. Confirm the scheduler's exact cron dialect and field count.
  3. Generate or edit the expression one field at a time.
  4. Test upcoming matches across a month boundary, weekend, and daylight-saving transition when relevant.
  5. Run the command manually with the same user, environment, and permissions.
  6. Verify logging, alerts, retries, timeouts, locking, and overlap behavior.
  7. Record the expression, owner, purpose, timezone, and last review date.

When a job behaves unexpectedly, begin by comparing the expression's next run times with the scheduler's documented timezone and implementation. Then inspect the command environment and execution logs. Treat the expression, the runtime, and the task's data behavior as three separate parts of the system; checking all three is faster and safer than repeatedly editing the schedule.

Related Topics

#cron#scheduling#automation#DevOps#backend
P

Programa Space Editorial Team

Developer Resources Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.