A cron expression is a compact way to describe when a recurring job should run. This guide explains cron syntax field by field, provides reusable schedule examples for Linux and cloud platforms, and gives you a practical checklist for verifying timezones, daylight-saving behavior, permissions, and missed executions before a scheduled task reaches production.
Overview
Traditional Unix cron uses five fields, read from left to right:
minute hour day-of-month month day-of-week command
Each field accepts a specific value, a range, a list, or a step. The asterisk means “every allowed value.” For example:
0 2 * * * /usr/local/bin/backup.sh
This runs the command at 02:00 every day, subject to the machine’s local timezone and the cron implementation’s behavior.
| Field | Allowed values in standard Unix cron | Examples |
|---|---|---|
| Minute | 0–59 | 0, 15, */10 |
| Hour | 0–23 | 2, 9-17, */4 |
| Day of month | 1–31 | 1, 1,15, */2 |
| Month | 1–12, sometimes names | 1, 6-8, JAN |
| Day of week | 0–7, where 0 or 7 commonly means Sunday | 1-5, MON-FRI |
Common operators are easy to combine:
*: every permitted value, such as every hour.*/n: every n units, such as*/15for every 15 minutes.a-b: an inclusive range, such as9-17.a,b,c: a list of selected values, such as1,15.
Do not assume that every scheduler supports the same syntax. Some cloud schedulers use six fields and put seconds first; others use a question mark, a year field, or a different timezone configuration. Confirm the target platform’s format before copying a Linux crontab expression into a hosted scheduler.
Checklist by scenario
Every few minutes or hours
Use a step expression when the schedule is an interval within the field’s normal cycle:
*/5 * * * * /path/to/check.sh
0 */4 * * * /path/to/report.sh
The first command runs every five minutes. The second runs at minute zero every four hours. If you need “every four hours from the moment the previous job finished,” cron is usually the wrong model; use a worker, timer, or scheduler that supports interval-based execution and overlap control.
Once per day
30 1 * * * /path/to/nightly-task.sh
This represents 01:30 each day. Use an absolute path to the executable and consider writing output to a log so that a silent failure is not mistaken for a successful run.
Weekdays during working hours
0 9-17 * * 1-5 /path/to/business-hours-task.sh
This runs at the top of each hour from 09:00 through 17:00, Monday through Friday. If the task must run only once during that period, use a single hour instead of a range.
On selected dates
0 3 1,15 * * /path/to/maintenance.sh
0 0 * * 0 /path/to/weekly-cleanup.sh
The first expression runs on the first and fifteenth day of each month. The second commonly represents midnight on Sunday. Verify the day-of-week numbering in the scheduler you are using.
Linux crontab entries
Edit a user’s crontab with crontab -e, then add the five schedule fields followed by the command. A useful pattern is:
SHELL=/bin/sh
PATH=/usr/local/bin:/usr/bin:/bin
15 2 * * * /opt/jobs/export.sh >> /var/log/export.log 2>&1
Defining PATH and redirecting output makes the environment more predictable and gives you evidence to inspect when the job fails. System-wide cron files may include an additional username field, so do not paste a user crontab line into a system configuration file without checking its format.
Cloud schedulers and six-field formats
Managed schedulers often separate the expression from the target action and may use a six-field format. A common pattern is:
0 30 2 * * ?
In systems that place seconds first, this can mean 02:30 daily, but the exact interpretation depends on the provider. Treat this as a format illustration, not a universal cloud expression. Record the provider, expression format, configured timezone, retry policy, and destination when you create the schedule.
Using a cron expression generator
A cron expression generator or online cron builder can reduce typing errors, but it should be used as a verification aid rather than the final authority. Enter the intended frequency, inspect the generated fields, and compare the next several run times with your requirements. Pay particular attention to whether “day of month” and “day of week” are combined with AND or OR behavior.
What to double-check
- Timezone: Identify whether the schedule uses the host timezone, UTC, a scheduler-level timezone, or a job-specific setting. Store the chosen timezone beside the expression in documentation.
- Daylight saving time: A local time can occur twice when clocks move backward or not occur at all when clocks move forward. For billing, reporting, and other time-sensitive jobs, decide whether UTC or an explicit business timezone is the correct basis.
- Next run times: Test the expression with a trusted parser or scheduler preview and inspect several future occurrences, including a month boundary and a daylight-saving transition where relevant.
- Command context: Cron may run with a limited environment, a different working directory, and a different user. Use absolute paths, load configuration deliberately, and never assume an interactive shell’s aliases or variables are available.
- Permissions and secrets: Confirm that the executing user can read required files, write output, access the network, and retrieve credentials without placing sensitive values directly in a world-readable crontab.
- Overlap and duration: If a job can run longer than its interval, determine whether concurrent executions are safe. Add a lock, idempotency key, queue, or platform-specific concurrency limit when necessary.
- Failure visibility: Send logs to a known location and define an alerting path. A scheduler starting a process does not necessarily mean the process completed successfully.
For tasks that process timestamps or generate reports, pair the schedule review with a date-and-time implementation review. The JavaScript date and time formatting cookbook and the guide to SQL date and time functions are useful when the scheduler’s timezone and the application’s timezone must agree.
Common mistakes
- Confusing “every five minutes” with “at minute five”:
*/5means every five minutes;5means once at five minutes past each hour. - Using six fields in a five-field crontab: A seconds field can shift every value and produce an entirely different schedule.
- Expecting missed runs to be replayed: Traditional cron generally evaluates the current time; it does not automatically provide durable catch-up behavior. Use a scheduler with explicit catch-up support when missed executions matter.
- Forgetting month boundaries: “The last day of every month” is not represented consistently by basic cron syntax. A daily job with a date check may be safer, or the platform may provide a dedicated last-day feature.
- Ignoring command exit status: A script can start and still fail halfway through. Make scripts return meaningful exit codes and log important steps.
- Relying on local time without documenting it: A server migration or container change can alter the effective timezone and shift every execution.
When a job is missing, troubleshoot in order: confirm the expression and next run time, check the scheduler or cron service, verify the executing user, run the command manually with the same environment, inspect logs, and then check locks, network access, credentials, and downstream failures. This separates scheduling problems from application problems.
When to revisit
Review a cron schedule before seasonal planning cycles, reporting-period changes, daylight-saving transitions, infrastructure migrations, and any change to the command or its dependencies. Revisit it whenever a workflow moves from a server crontab to a container platform or managed cloud scheduler, because the field count, timezone defaults, retries, and failure handling may change.
Keep a small schedule record with the expression, plain-language description, timezone, owner, expected duration, overlap policy, log location, and alerting destination. After changing the expression, verify at least the next three run times and perform one controlled execution. If the job affects data or external systems, test it against a safe target before enabling production writes.
Use this final checklist before committing a scheduled job:
- Write the desired schedule in plain language.
- Translate it using the target scheduler’s documented field order.
- Preview future run times in the intended timezone.
- Confirm permissions, paths, configuration, and secrets.
- Decide how retries, overlaps, missed runs, and failures are handled.
- Record the owner and revisit date next to the schedule.
A cron expression is only one part of reliable automation. The surrounding command, runtime environment, timezone, observability, and recovery behavior determine whether the scheduled workflow is safe to operate.