Cron Expressions Made Simple: Syntax, Examples, Time Zones, and Common Mistakes
cronautomationDevOpsschedulingLinux

Cron Expressions Made Simple: Syntax, Examples, Time Zones, and Common Mistakes

CCode Compass Editorial Team
2026-11-30
7 min read

Learn cron expression syntax, compare scheduler variants, handle time zones and DST, and troubleshoot overlaps, missed jobs, and logging.

Cron expressions turn a plain-language schedule into a compact rule, but a small punctuation mistake can run a job at the wrong time—or not at all. This guide explains cron expression syntax field by field, compares common scheduler variants, provides practical cron schedule examples, and gives you a repeatable checklist for time zones, daylight saving time, overlapping runs, missed jobs, logging, and safe verification.

Overview

A traditional Unix cron expression has five fields separated by spaces:

minute hour day-of-month month day-of-week
  0-59   0-23       1-31       1-12       0-7

The expression is followed by the command to run. For example:

30 2 * * * /usr/local/bin/backup.sh

This means “run at 02:30 every day,” assuming the scheduler uses the host’s local time zone. An asterisk means every valid value. A comma lists separate values, a hyphen defines a range, and a slash defines a step:

  • 1,15,30 means at minutes 1, 15, and 30.
  • 9-17 means every value from 9 through 17.
  • */10 means every tenth value, such as minutes 0, 10, 20, 30, 40, and 50.

Some cron implementations also accept names such as MON and JAN. Numeric day-of-week values commonly use 0 or 7 for Sunday, but name and numbering support varies. Check the scheduler’s documentation before moving an expression between systems.

Use a cron expression guide and testing workflow to verify the expression in the same syntax as the system that will execute it. A cron builder can help explain a rule, but it cannot determine how a particular server, container, or hosted platform handles time zones and missed executions.

What to track

Field-by-field syntax

FieldTypical valuesExampleMeaning
Minute0–5915At 15 minutes past the hour
Hour0–236At 06:00 in a 24-hour clock
Day of month1–311On the first day of the month
Month1–124-9From April through September
Day of week0–71-5Usually Monday through Friday

Here are useful cron schedule examples for recurring maintenance:

# Every five minutes
*/5 * * * * /usr/local/bin/health-check.sh

# At 01:15 every Sunday
15 1 * * 0 /usr/local/bin/weekly-report.sh

# At 04:00 on the first day of every month
0 4 1 * * /usr/local/bin/monthly-cleanup.sh

# At 09:00 and 17:00 on weekdays
0 9,17 * * 1-5 /usr/local/bin/sync.sh

# Every 15 minutes during business hours, Monday through Friday
*/15 9-17 * * 1-5 /usr/local/bin/poll.sh

Be precise about phrases such as “every 15 minutes.” */15 runs on clock-aligned minutes—0, 15, 30, and 45—not 15 minutes after the previous run finishes. If a job takes longer than its interval, executions may overlap unless the command or scheduler prevents that.

Scheduler differences

Scheduler or formatCommon shapeImportant difference
Unix-style crontab5 fields plus commandUsually minute through day-of-week; local environment and time zone matter.
System crontab5 fields plus user plus commandSome system files add a user field, so copying a user crontab line directly can be wrong.
Quartz-style schedulers6 or 7 fieldsOften includes seconds and uses ? for an unspecified day field.
Hosted schedulersProvider-definedMay use UTC by default, restrict syntax, or add retry and delivery behavior.
systemd timersCalendar expressionsNot a cron parser; supports a different format and service-based execution model.

Do not assume that an expression accepted by one cron expression generator is valid everywhere. Confirm the number of fields, supported symbols, time-zone setting, and whether day-of-month and day-of-week conditions are combined with the behavior you expect. In many traditional cron implementations, specifying both fields can match when either restricted condition is true, rather than requiring both conditions simultaneously. Test this case explicitly.

Operational details

A cron rule is only one part of a reliable job. Record the command’s absolute path, required environment variables, expected working directory, output destination, timeout, retry policy, and whether concurrent runs are safe. Cron often starts commands with a smaller environment than an interactive shell, so a script that works in your terminal may fail when invoked by cron.

Redirect output deliberately:

0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

Use a lock when a second run must not start before the first has finished. On systems that provide it, a pattern such as flock -n /run/backup.lock /usr/local/bin/backup.sh can prevent overlap. Otherwise, implement an equivalent lock with a clearly defined stale-lock recovery strategy.

Cadence and checkpoints

Check a new schedule before enabling it in production. Write the intended behavior in plain language, generate or edit the expression, then list the next several trigger times in the scheduler’s actual time zone. Include boundary dates: the end of a month, a month transition, a weekday transition, and any daylight saving time change relevant to the host.

For a monthly or quarterly review, inspect these checkpoints:

  1. Expression: Does the stored rule still match the business requirement?
  2. Execution: Did the job start at the expected local or UTC time?
  3. Duration: Is runtime approaching the interval between executions?
  4. Result: Did the command complete successfully, and is its output usable?
  5. Logs: Are standard output, errors, exit codes, and alerts retained long enough to investigate failures?
  6. Dependencies: Have paths, credentials, containers, databases, APIs, or network permissions changed?

For backups and destructive maintenance, perform a controlled test separately from the normal schedule. Confirm not only that the command starts, but also that it creates the expected artifact, reports failure clearly, and can be recovered if the process stops halfway through.

How to interpret changes

A job that runs at the wrong time is usually a time-zone or syntax problem, not an execution-speed problem. First identify the scheduler’s time zone and compare it with the time zone assumed when the expression was written. A server may use UTC while an operator is thinking in local time. Some implementations support a setting such as CRON_TZ, but support and scope differ; a scheduler-level configuration or hosted-platform setting may take precedence.

Daylight saving time creates two unusual cases. A local time can occur twice when clocks move backward, or not occur at all when clocks move forward. Cron implementations differ in whether they skip, repeat, or otherwise handle those timestamps. For jobs that must run exactly once, consider a UTC schedule, a scheduler with explicit time-zone and misfire semantics, or application logic that records an idempotency key.

A missed run is not automatically replayed. Traditional cron generally checks the current schedule rather than maintaining a durable queue of missed executions. If a job must catch up after downtime, use a scheduler or script that records the last successful execution and processes an explicit time window. Make the operation idempotent so a retry does not duplicate data or send repeated notifications.

If logs show overlapping runs, compare job duration with its interval and inspect retries from the surrounding platform. Add a lock, increase the interval, split the work, or move the task to a queue with concurrency controls. If there are no logs, first verify that the crontab is installed for the expected user, the command has executable permissions, the interpreter path is valid, and output is redirected somewhere you can read.

For failures involving application data, pair cron troubleshooting with an operational checklist. The SQL query optimization checklist is useful when a scheduled database task becomes slow, while the Browser DevTools network guide helps investigate scheduled workflows that depend on web APIs.

When to revisit

Revisit a cron expression whenever its command, host, container image, account, time zone, dependency, or business requirement changes. Also review it before and after daylight saving time transitions when the schedule uses local time, and after migrating from a server crontab to a hosted scheduler, CI platform, container platform, or Quartz-like service. Syntax that was valid in one environment may be rejected or interpreted differently in another.

Use this practical review sequence:

  1. Copy the exact expression and command from the deployed configuration.
  2. State the intended schedule in plain language, including its time zone.
  3. Check the parser and field count for the target scheduler.
  4. Preview upcoming run times, including month-end and DST boundaries.
  5. Run the command manually with the same user, working directory, and environment where possible.
  6. Test logging, locking, failure alerts, retries, and recovery.
  7. Record the owner, purpose, last review date, and next review date.

For a small number of jobs, a documented crontab and a quarterly review may be enough. As schedules become business-critical, centralize ownership and execution history rather than relying on memory or a single server. Treat every cron rule as production configuration: simple to write, but worth verifying at the boundaries where time, environments, and failures behave differently.

Related Topics

#cron#automation#DevOps#scheduling#Linux
C

Code Compass 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.