A reliable cron schedule starts with more than memorizing five fields. This guide explains how to build, validate, deploy, and maintain recurring jobs while accounting for ranges, lists, steps, time zones, daylight-saving changes, missed runs, and differences between schedulers.
Overview
Cron is a time-based automation system used to start commands or workflows on a recurring schedule. A traditional Unix-style cron expression has five fields followed by the command:
minute hour day-of-month month day-of-week command
For example:
30 2 * * 1 /path/to/backup.sh
This commonly means “run the command at 02:30 every Monday,” but the exact interpretation depends on the scheduler. Hosted platforms, CI systems, container tools, and application libraries may use six or seven fields, include a seconds field, require a special timezone setting, or use a different weekday numbering convention. Treat a cron expression generator or cron job validator as a starting point, not as a substitute for checking the target platform’s syntax.
Field-by-field reference
| Field | Typical values | Meaning | Example |
|---|---|---|---|
| Minute | 0–59 | Minute within the hour | 15 runs at 15 minutes past |
| Hour | 0–23 | Hour of the day in the scheduler’s timezone | 6 runs during the 06:00 hour |
| Day of month | 1–31 | Calendar day | 1 means the first day of the month |
| Month | 1–12 or names | Month of the year | 1,7 means January and July |
| Day of week | 0–7 or names | Day in the weekly cycle | 1-5 often means Monday through Friday |
An asterisk means “any permitted value.” A comma creates a list, a hyphen creates a range, and a slash creates a step. Therefore, 0,30 means two selected minutes, 9-17 means a range, and */10 means every tenth permitted value. Names such as MON or JAN may be accepted, but numeric values are usually easier to compare across tools.
Checklist by scenario
To run a job once every day
- Choose the intended local time and confirm whether it is operationally safe.
- Convert that time to the scheduler’s timezone rather than assuming the server uses your local timezone.
- Use a five-field expression such as
0 3 * * *for a daily run at 03:00 in a traditional cron environment. - Confirm that the command has an absolute path, required environment variables, and permission to run.
- Test the command independently before testing the schedule.
To run a job on selected weekdays
Use a list or range in the weekday field. A weekday business-hours pattern might be:
0 9-17 * * 1-5 /path/to/task
This requests the top of every hour from 09:00 through 17:00, Monday through Friday, in implementations that follow the usual five-field convention. If you need only 09:00, 13:00, and 17:00, use an explicit list instead:
0 9,13,17 * * 1-5 /path/to/task
Check whether the scheduler treats day-of-month and day-of-week as an inclusive alternative when both are restricted. That behavior is common in traditional cron, while some newer schedulers document a different rule.
To run at regular intervals
Step syntax is useful for recurring intervals:
*/15 * * * * /path/to/check
This generally means every 15 minutes, starting at minute 0 of each hour. It does not necessarily mean “15 minutes after the previous run finishes.” If the task takes longer than its interval, overlapping processes may occur. Add a lock, queue, or platform-specific concurrency control when overlap could duplicate work or corrupt data.
To run on a monthly date
0 1 1 * * /path/to/monthly-task
This schedules a run at 01:00 on the first day of each month. If the intended rule is “the last day of every month,” do not assume that a traditional five-field expression can express it directly. Use a supported special syntax, a wrapper script that checks the date, or an application scheduler that explicitly supports calendar rules.
To use a hosted scheduler or CI platform
- Read the platform’s cron documentation before copying a Linux example.
- Check whether seconds are required or allowed.
- Identify the default timezone and whether a timezone can be configured.
- Confirm whether the schedule triggers a command, a workflow, an HTTP request, or a deployment job.
- Check whether the platform skips, queues, or coalesces runs when a previous execution is still active.
- Review the platform’s behavior after downtime, failed deployment, or a missed trigger.
When using a cron expression generator or validator
Enter the intended rule in plain language first: “at 04:20 UTC every Tuesday,” for example. Generate the expression, then verify it by inspecting several next-run times. A validator can catch invalid ranges and field counts, but it cannot know whether the job is safe to run during a maintenance window, whether the timezone is correct, or whether the command is idempotent.
What to double-check
Timezone and daylight-saving behavior
Write the timezone next to every production schedule in documentation and configuration. “02:00 daily” is incomplete without saying where 02:00 occurs. A server may run in UTC while the business requirement is based on a regional timezone. During daylight-saving transitions, a local time may occur twice or not occur at all. The scheduler may skip a run, run it twice, interpret the expression in UTC, or apply its own documented rule.
For jobs tied to a fixed elapsed interval, UTC or an interval-based mechanism may be clearer. For jobs tied to a human calendar, such as local payroll processing, explicitly configure the intended regional timezone and test the transition behavior.
Environment and command context
Cron often runs with a smaller environment than an interactive shell. Use absolute paths for executables and files, define required variables explicitly, and set a working directory when the command depends on relative paths. Redirect output to a controlled log location or use the scheduler’s logging facility. Avoid placing credentials directly in a crontab entry; use the platform’s secret store or a protected configuration method.
Missed runs and retries
Decide what should happen if the host is offline or the workflow is disabled at the scheduled time. Some schedulers do nothing; others offer catch-up or persistence options. A daily report may need one catch-up run, while a cleanup task may be safe to skip. Document whether the task should retry, how many times it should retry, and how it avoids processing the same period twice.
Observability and safety
Every important scheduled job should have a visible success and failure signal. Record the scheduled time, actual start time, duration, exit status, and useful identifiers such as the date range processed. Add an alert for repeated failures, but avoid creating noisy alerts for expected skips. Before enabling a destructive command, run it in a dry-run mode or against a controlled dataset.
For workflows that call APIs, validate the request and response contract as part of deployment. The OpenAPI validation workflow can help teams check API assumptions before an automated job begins depending on them.
Common mistakes
- Confusing “every N minutes” with a delayed interval:
*/20usually aligns to clock minutes such as 00, 20, and 40. It does not wait 20 minutes after completion. - Assuming all cron dialects match: A standard five-field expression may fail in a scheduler that expects seconds, a year field, or a special syntax.
- Forgetting the timezone: A correct expression in the wrong timezone is still an operational error.
- Ignoring overlap: A long-running task can start again before the previous process finishes. Use locking or concurrency limits where necessary.
- Using relative paths: Interactive shell behavior does not guarantee cron behavior. Prefer explicit paths and working directories.
- Testing only the expression: A valid schedule does not prove that the command, permissions, secrets, network access, or dependencies are valid.
- Relying on day names without checking numbering: Some tools accept both 0 and 7 for Sunday, while others document different conventions.
- Assuming a missed run will be recovered: Define catch-up behavior rather than discovering it after downtime.
When to revisit
Revisit a cron schedule before seasonal planning cycles, timezone changes, infrastructure migrations, or any workflow redesign. Also review it when moving between Linux distributions, containers, hosted schedulers, CI platforms, or application-level job runners. Syntax compatibility, default timezone, logging, retry behavior, and missed-run handling can change even when the visible expression remains the same.
Use this practical deployment checklist:
- Write the requirement in plain language, including timezone and expected frequency.
- Confirm the target scheduler’s field count, supported operators, and weekday rules.
- Generate or write the expression, then validate it with the target platform.
- Inspect several next-run times, including a month boundary and a daylight-saving transition when relevant.
- Run the command manually with the same user, environment, and working directory.
- Test failure, retry, overlap, and missed-run behavior.
- Document the owner, purpose, timezone, dependencies, and rollback or disable procedure.
- After deployment, confirm both the trigger and the job’s business result.
Keep the expression beside its explanation rather than treating it as self-documenting code. When a workflow changes, update the schedule, its tests, and its operational notes together. That small habit makes a cron job easier to audit and safer to migrate.