A reliable cron schedule starts with a clear task, a known timezone, and a way to verify what happened. This guide explains how to write and check cron expressions for backups, reports, scripts, deployments, and recurring website maintenance, with practical examples and a review routine that helps prevent silent failures.
Overview
Cron is a time-based job scheduler commonly available on Unix-like systems. A cron job runs a command or script according to a schedule written as a cron expression. Typical uses include creating database backups, sending reports, clearing temporary files, checking an endpoint, or running an application maintenance task.
A standard five-field cron expression describes when a command should run:
| Field | Allowed values | Meaning |
|---|---|---|
| Minute | 0–59 | Minute of the hour |
| Hour | 0–23 | Hour of the day, usually in server time |
| Day of month | 1–31 | Calendar day |
| Month | 1–12 or names in some implementations | Month of the year |
| Day of week | 0–7 or names in some implementations | Day of the week; 0 and 7 often represent Sunday |
The five fields are followed by the command:
minute hour day-of-month month day-of-week commandFor example:
30 2 * * * /usr/local/bin/backup-site.shThis requests a run at 02:30 every day, assuming the host uses a standard five-field cron format. Cron syntax differs across platforms and scheduling services, so confirm the implementation before moving a production task. Some systems add a seconds field, a year field, special shortcuts, or a different interpretation of day-of-month and day-of-week.
What to track
Writing the expression is only one part of reliable scheduling. Track the schedule, the task, the execution environment, and the result.
1. The intended schedule
Write the schedule in plain language before converting it into syntax. “At 02:30 every day in the server’s timezone” is easier to review than 30 2 * * *. Record whether the requirement is exact or approximate. A nightly backup may tolerate a few minutes of variation, while a time-sensitive integration may need a more controlled scheduler.
2. The command and working context
Use an absolute path to the executable and, where practical, an absolute path to files. Cron may run with a smaller environment than an interactive shell. A command that works in your terminal can fail because PATH, the working directory, application variables, or credentials are unavailable.
15 1 * * * /usr/bin/php /var/www/example/artisan reports:generate >> /var/log/example-reports.log 2>&1The example runs a PHP command at 01:15 and appends both standard output and errors to a log. Adjust paths, permissions, and logging locations for your platform.
3. The timezone
Record the timezone used by the scheduler, not just the timezone used by the team. A server may be configured for UTC while the business operates in another region. Hosting dashboards, containers, managed platforms, and application-level schedulers may each handle timezone settings differently.
Daylight-saving changes deserve special attention. A job scheduled during a skipped local hour may not run when expected; a job during a repeated hour may run once or more than once, depending on the scheduler. For important work, use an explicit timezone where the platform supports it, choose a schedule that avoids ambiguous times, and make the task safe to retry.
4. Success, failure, and duration
Track more than whether a process started. A useful record includes the expected run time, actual start and finish times, exit status, output location, and whether the result was complete. A backup command that exits successfully but produces an empty or inaccessible archive still needs attention.
5. Permissions and secrets
Run jobs with the least privilege they require. Avoid placing passwords or API tokens directly in a crontab where other users or automated diagnostics could expose them. Prefer a protected environment file, a secrets facility, or the hosting platform’s credential mechanism. Restrict script permissions and validate any input passed to shell commands.
Cadence and checkpoints
A cron expression should be checked at several points: when it is created, after deployment, after a server or region change, and during routine operations review.
| Checkpoint | What to verify |
|---|---|
| Before enabling | Plain-language intent, syntax, timezone, command paths, permissions, and expected runtime |
| First scheduled run | Start time, exit status, output, generated files, notifications, and side effects |
| After infrastructure changes | Server timezone, user account, environment variables, mounted paths, network access, and log locations |
| Monthly or quarterly review | Whether the job is still needed, duration trends, failure history, storage growth, and alert coverage |
| After a missed run | Scheduler status, system logs, overlapping jobs, resource limits, lock files, and downstream dependencies |
Use a cron expression builder or a local test utility to inspect the next expected run times, but treat the result as a syntax check rather than proof that the task will succeed. The host’s timezone, shell, permissions, and platform restrictions still need to be tested.
Common cron expression examples
| Expression | Plain-language meaning |
|---|---|
*/5 * * * * | Every five minutes |
0 * * * * | At the start of every hour |
0 3 * * * | Every day at 03:00 |
0 4 * * 0 | Every Sunday at 04:00 in implementations where 0 means Sunday |
30 8 * * 1-5 | At 08:30 Monday through Friday |
0 0 1 * * | At midnight on the first day of each month |
10 2 1,15 * * | At 02:10 on the first and fifteenth days of each month |
Do not assume that a list, range, or step behaves identically in every scheduler. Verify the expression against the documentation for the target environment.
How to interpret changes
When a scheduled task changes, compare the observed behavior with the intended schedule rather than editing the expression immediately. A missed run can result from an invalid expression, the wrong timezone, a disabled scheduler, a failed command, a locked file, a full disk, a timeout, or a platform restriction.
If the job runs at the wrong time
Check the host timezone first, then inspect whether the scheduler or application applies its own timezone. Confirm daylight-saving behavior and compare the recorded execution timestamp with the system clock. Avoid “fixing” the expression by adding an offset until the timezone source is known; that workaround can become wrong after a server migration or seasonal clock change.
If the job never runs
Confirm that the crontab or scheduled task is installed for the intended user and that the scheduler service is active. Run the command manually as that user using the same absolute paths. Check file permissions, interpreter paths, environment variables, and system logs. Redirect output temporarily or use structured application logging so that errors are visible.
If the job runs more than once
Look for duplicate entries, multiple application instances, overlapping deployments, or more than one scheduler invoking the same task. Add a lock or application-level idempotency check when duplicate execution could create duplicate reports, charge an account twice, or overwrite data.
If the job becomes slow
Compare recent duration with earlier runs and inspect input volume, database load, network dependencies, disk space, and concurrent tasks. A frequent job should finish comfortably before its next scheduled start, or it should use a lock and a queue to prevent overlap. For long-running workflows, a dedicated job system may be safer than a simple cron command.
When to revisit
Revisit every cron job at least monthly or quarterly, depending on its impact. High-risk tasks such as backups, billing workflows, security checks, and production deployments deserve more frequent verification and a clear alert when they fail. Low-risk housekeeping jobs can usually follow a quarterly review.
Use this compact planning template for each task:
- Purpose: What does the job do, and what depends on its result?
- Expression: What is the exact schedule and its plain-language translation?
- Timezone: Which system or application timezone controls execution?
- Command: Which user, interpreter, paths, variables, and credentials are required?
- Evidence: Where are exit codes, logs, outputs, and alerts recorded?
- Recovery: Can the task be safely retried, and what is the manual fallback?
- Review date: When will duration, failures, storage, and business need be checked again?
Update the record after changing hosting regions, deployment workflows, application versions, backup destinations, or server permissions. If a scheduled task affects a website, test it in a staging environment before production; the staging website and safe deployment workflow guide provides a related checklist. For backup jobs, pair the schedule with a documented backup and disaster recovery plan, and monitor important endpoints and alerts using a defined uptime incident runbook.
Finally, verify one real run after every meaningful change. A cron expression is only a promise about timing; logs, exit codes, usable outputs, and a tested recovery path show whether the promise was kept.