What Is Cron?
Cron is a time-based job scheduler in Unix-like operating systems. It runs commands or scripts at specified intervals — hourly, daily, weekly, or on a custom schedule. The schedule is defined using a cron expression: a compact string of five or six fields that specify when the job should run.
Beyond Linux cron, the same expression format is used by GitHub Actions, AWS CloudWatch Events, Kubernetes CronJobs, Heroku Scheduler, and most cloud task scheduling services.
Cron Expression Syntax
A standard cron expression has five fields representing time units:
┌───────── minute (0–59)
│ ┌─────── hour (0–23)
│ │ ┌───── day of month (1–31)
│ │ │ ┌─── month (1–12 or JAN–DEC)
│ │ │ │ ┌─ day of week (0–7, where 0 and 7 = Sunday, or SUN–SAT)
│ │ │ │ │
* * * * * command
Some systems (Spring, Quartz, AWS) add a sixth field for seconds at the beginning: second minute hour day month weekday.
Special Characters
| Character | Meaning | Example |
|---|---|---|
* | Every value | * * * * * — every minute |
, | List of values | 0 9,17 * * * — at 9:00 AM and 5:00 PM |
- | Range of values | 0 9-17 * * * — every hour from 9 AM to 5 PM |
/ | Step value | */15 * * * * — every 15 minutes |
L | Last (some systems) | 0 0 L * * — last day of each month |
W | Nearest weekday (some systems) | 0 0 15W * * — nearest weekday to the 15th |
# | Nth occurrence (some systems) | 0 0 * * 2#1 — first Monday of month |
Common Cron Expressions
# Every minute
* * * * *
# Every 5 minutes
*/5 * * * *
# Every hour (at minute 0)
0 * * * *
# Every day at midnight
0 0 * * *
# Every day at 9:30 AM
30 9 * * *
# Every weekday (Monday–Friday) at 8 AM
0 8 * * 1-5
# Every Monday at 9 AM
0 9 * * 1
# First day of every month at midnight
0 0 1 * *
# Every quarter (Jan, Apr, Jul, Oct) on the 1st at noon
0 12 1 1,4,7,10 *
# Every Sunday at 2 AM (common for maintenance windows)
0 2 * * 0
# Every 30 minutes during business hours (9 AM to 5 PM), weekdays
*/30 9-17 * * 1-5
Special Strings (Linux cron)
Linux cron supports shorthand strings as alternatives to five-field expressions:
| String | Equivalent | Meaning |
|---|---|---|
@reboot | — | Run once at startup |
@yearly | 0 0 1 1 * | Once a year (Jan 1) |
@monthly | 0 0 1 * * | Once a month (1st day) |
@weekly | 0 0 * * 0 | Once a week (Sunday) |
@daily | 0 0 * * * | Once a day (midnight) |
@hourly | 0 * * * * | Once an hour |
Timezone Considerations
Cron jobs run in the server's local timezone by default. This creates problems when:
- Your server is in UTC but your users are in New York (UTC-5)
- Daylight Saving Time changes cause jobs to run an hour early or late
- You deploy to servers in different timezones
Best practice: Always set cron jobs in UTC and handle timezone conversion in your application code. Most cloud schedulers (AWS EventBridge, Google Cloud Scheduler) allow you to specify a timezone explicitly.
# Linux — set timezone per cron job (GNU cron extension)
CRON_TZ=America/New_York
0 9 * * 1-5 /path/to/script.sh
Cron in Modern Infrastructure
Kubernetes CronJob
apiVersion: batch/v1
kind: CronJob
metadata:
name: daily-cleanup
spec:
schedule: "0 2 * * *" # 2 AM UTC daily
jobTemplate:
spec:
template:
spec:
containers:
- name: cleanup
image: my-app:latest
command: ["python", "cleanup.py"]
GitHub Actions
on:
schedule:
- cron: "0 6 * * 1" # Every Monday at 6 AM UTC
Common Pitfalls
- Day-of-month AND day-of-week — When both are specified (not
*), cron uses OR logic, not AND.0 0 15 * 1runs on the 15th or every Monday — not on Mondays that are the 15th. - Overlapping jobs — If a job takes longer than its interval, multiple instances can run simultaneously. Use
flockor your scheduler's concurrency policy to prevent this. - No output monitoring — By default, cron emails stdout/stderr to the local system user. Redirect output to a log file and set up alerting for failed jobs.
- Environment differences — Cron runs with a minimal environment (different
PATH, no shell profile). Use absolute paths for commands and binaries.
Test Your Cron Expressions
Use the Copynix Cron Expression Builder to build and validate cron expressions interactively. See the human-readable schedule description and the next 5 execution times — no configuration needed, runs entirely in your browser.
Summary
Cron expressions are a five-field time specification covering minute, hour, day-of-month, month, and day-of-week. Master the special characters (*, /, -, ,) and you can express almost any schedule. Always use UTC in production, use absolute paths in cron scripts, and implement locking for long-running jobs.
