Writing a cron expression is straightforward once each field has a clear meaning, but small errors can cause backups, reports, deployments, or cleanup tasks to run at the wrong time—or not run at all. This guide explains cron syntax field by field, provides practical cron schedule examples, compares common cron variants, and gives you a repeatable audit process for reliable cloud scheduled jobs.
Overview
A cron expression is a compact schedule made from several space-separated fields. A scheduler evaluates those fields against the current date and time, then starts a command or task when the values match. On a traditional Unix-like system, a cron job may run a shell command, script, or application task. In a cloud environment, the same idea may appear as a managed scheduler, a platform timer, a container task, or a serverless scheduled function.
The most familiar five-field cron format is:
minute hour day-of-month month day-of-week
For example:
30 2 * * *
This commonly means “run at 02:30 every day,” assuming the scheduler uses the intended timezone. The five fields describe when a task should start; they do not by themselves guarantee that the task will finish, retry after failure, avoid overlapping executions, or preserve logs. Reliable automation requires both a correct expression and an operational plan.
Before deploying a schedule, identify the task’s purpose, acceptable delay, expected runtime, timezone, permissions, failure behavior, and output location. A cron expression builder or schedule preview can help validate the calendar pattern, but the preview should be checked against the documentation for the scheduler that will actually execute the job.
What to track
The five standard cron fields
| Field | Typical values | Meaning |
|---|---|---|
| Minute | 0–59 | The minute within the hour |
| Hour | 0–23 | The hour of the day in 24-hour time |
| Day of month | 1–31 | The calendar day |
| Month | 1–12 | The month, from January through December |
| Day of week | 0–7 | The weekday; numbering and Sunday representation vary by implementation |
An asterisk (*) means “every allowed value.” A comma lists separate values, a hyphen defines a range, and a slash defines an interval. For example:
0,30means at minute zero and minute thirty.9-17means each value from 9 through 17.*/15means every fifteen units within the field’s range.
Some schedulers also support names such as MON or JAN, a seconds field, a year field, a question mark, a last-day operator, or a special syntax such as “every five minutes.” These features are not portable. Use numeric, five-field syntax when portability matters, and confirm the accepted format before copying an expression between a Linux host, a hosting control panel, a CI platform, and a cloud scheduler.
Useful cron schedule examples
| Expression | Plain-language schedule | Typical use |
|---|---|---|
0 0 * * * | At midnight every day | Daily maintenance or data preparation |
30 2 * * * | At 02:30 every day | Overnight backup or cleanup |
0 8 * * 1-5 | At 08:00 Monday through Friday | Business-day report generation |
0 */6 * * * | At the start of every sixth hour | Periodic synchronization |
15 9 1 * * | At 09:15 on the first day of each month | Monthly billing or review task |
0 18 * * 0 | At 18:00 every Sunday | Weekly report or housekeeping |
These examples assume standard five-field cron behavior and a known timezone. They should not be treated as universal commands. If a task must run once per month at the end of the month, a simple day-of-month value may be insufficient because months have different lengths. In that case, use a scheduler feature designed for month-end behavior or run a daily check that exits unless the date is the final calendar day.
Standard cron versus platform-specific schedules
Traditional crontab entries usually contain five time fields followed by a command. A managed cloud scheduler may separate the schedule from the target, require six fields including seconds, include a year field, or use a different interpretation of day-of-month and day-of-week. Some systems use a dedicated timezone setting; others interpret expressions in UTC by default.
Do not assume that an expression copied from a cron syntax generator is valid everywhere. Check four things in the target platform’s documentation: field count, allowed ranges, special operators, and timezone behavior. Also confirm whether the platform sends an event to your application or executes a command directly. The task may need its own authentication, network access, environment variables, and timeout settings.
Cadence and checkpoints
Review a scheduled job at three levels: before launch, after the first runs, and during a recurring operational review.
Before launch
- Write the schedule in plain language. For example, “at 02:30 every day in the database’s local timezone.” If the expression cannot be explained clearly, do not deploy it.
- Confirm the timezone. Record the scheduler timezone beside the expression rather than relying on memory.
- Estimate runtime and frequency. A job scheduled every ten minutes must reliably finish, or be safely prevented from overlapping, before the next trigger.
- Test the command independently. Verify paths, credentials, environment variables, working directories, and file permissions using the same execution identity as the scheduler.
- Define logs and alerts. Capture start time, completion time, result, useful error details, and a correlation or run identifier where possible.
After deployment
Inspect the first several executions rather than assuming that a successful deployment proves the schedule works. Check the actual start time, duration, exit status, output, and side effects. A job can trigger correctly while still failing because a cloud resource is unavailable, a token has expired, or the application is using a different configuration in the scheduled environment.
During a monthly or quarterly review
Maintain a small inventory containing the job name, owner, purpose, expression, timezone, target, expected runtime, permissions, retry policy, last successful run, and retention period for logs. Review this inventory monthly for critical jobs and at least quarterly for lower-risk tasks. Reconcile it with the scheduler so abandoned or duplicated jobs are removed.
How to interpret changes
A missed run does not always indicate a bad cron expression. First distinguish a scheduling problem from an execution problem. If no trigger event or process start was recorded, investigate the expression, timezone, platform status, disabled job, or scheduler permissions. If a run started but failed, investigate the command, application, dependencies, credentials, resource limits, and network path.
Watch for these patterns:
- Unexpected local time: The scheduler may use UTC while the team is reading the expression in local time.
- Duplicate work: Two expressions, deployments, or scheduler instances may target the same task.
- Overlapping runs: The task takes longer than its interval. Add a lock, idempotency check, queue, or concurrency limit appropriate to the application.
- Silent failure: The command exits without useful output or sends errors to an unmonitored location. Add structured logging and an alert path.
- Daylight-saving surprises: A local-time schedule may encounter a skipped or repeated clock hour. Decide whether the task should follow wall-clock time or a fixed UTC interval.
- Permission drift: A changed service account, secret, role, or filesystem permission prevents a previously working task from completing.
Design recurring tasks to be idempotent whenever practical: running the same job twice should not corrupt data or create duplicate records. For backups, reports, deployments, and notifications, define what happens after a timeout or partial completion. Retries should be bounded and should account for whether the operation can safely be repeated.
When to revisit
Revisit a cron expression whenever its task, owner, infrastructure, timezone, or expected timing changes. A quarterly review is a useful baseline for production automation, while critical backups, billing workflows, and customer notifications may warrant a monthly checkpoint. Review immediately after a migration to cloud hosting, a scheduler or operating-system upgrade, a change to daylight-saving rules in the relevant region, or a modification to authentication and permissions.
Use this short audit checklist:
- Can the expression be translated into one unambiguous sentence?
- Is the field count and syntax supported by the actual scheduler?
- Is the timezone recorded, tested, and appropriate for the business requirement?
- Are missed runs, retries, timeouts, and overlapping executions handled?
- Do logs show both successful and failed attempts?
- Is there a named owner and a documented purpose?
- Are credentials, permissions, and secrets still valid and minimal?
- Has the task been tested after the latest application or infrastructure change?
Keep the expression, its plain-language explanation, the target platform, and the review date together in version control or an operations register. That simple record turns a fragile one-line schedule into maintainable cloud automation. When the next backup, deployment, report, cleanup, or notification requirement appears, start with the same process: define the intended time, validate the platform’s cron variant, test the execution path, and schedule the next review.