Skip to main content
Tools Harbor

What is a cron job?

A cron job is a scheduled command that runs at fixed times or intervals on Unix-like systems. The schedule is one line — five space-separated fields called a cron expression — telling the cron daemon when to fire. Linux, macOS, Kubernetes, GitHub Actions and AWS use the same syntax.

Anatomy of a cron job

A crontab entry has two halves — the schedule (when) and the command (what):

*/5 * * * *  /usr/local/bin/backup.sh
└────┬────┘  └─────────┬─────────────┘
 Schedule         Command

The schedule itself is five fields, in this order:

FieldRangeExample
Minute0–59*/5 = every 5 minutes
Hour0–239 = 9 AM
Day of month1–311 = first of month
Month1–12* = every month
Day of week0–6 (Sun=0)1-5 = Mon–Fri

* means “any value”, */N means “every N units”, and a comma separates a list (1,15 matches the 1st and 15th). That covers most cron expressions you’ll meet.

How do I read a cron expression?

Translate field-by-field, left to right:

  • 0 9 * * 1 → minute 0, hour 9, any day-of-month, any month, day-of-week 1 → Mondays at 9:00.
  • 0 0 1 * * → minute 0, hour 0, day 1 of the month, any month, any day-of-week → midnight on the 1st of every month.
  • */15 * * * * → every 15 minutes, every hour, every day → every quarter hour, around the clock.
  • 0 2 * * 0 → minute 0, hour 2, any day-of-month, any month, Sunday → Sundays at 2 AM.

If you can’t decode an expression at a glance, paste it into the Cron Expression Builder — it shows the human-readable description and the next 5 fire times.

What kinds of work do cron jobs do?

Anything that needs to run on a schedule rather than in response to user actions:

Use caseWhenCron expression
Hourly log rotationevery hour, on the hour0 * * * *
Daily database backupevery day at 2 AM0 2 * * *
Weekly analytics reportMondays at 9 AM0 9 * * 1
Monthly invoice runmidnight on the 1st0 0 1 * *
Health-check pingevery 5 minutes*/5 * * * *
Cache warm-up before traffic peakweekdays at 8:55 AM55 8 * * 1-5

Where do cron jobs actually run?

The same 5-field syntax shows up everywhere — once you learn it, it transfers across platforms:

  • Linux & macOS — the cron (or crond) daemon reads /var/spool/cron/crontabs/<user>, plus /etc/crontab and /etc/cron.d/ for system jobs. Edit your user crontab with crontab -e.
  • KubernetesCronJob resources schedule pods. Same syntax in the schedule: field, but concurrencyPolicy (Allow / Forbid / Replace) determines what happens when a previous run is still going. The Kubernetes CronJob schedule generator walks through the full manifest with timezone, concurrency and starting-deadline fields.
  • GitHub Actionson: schedule: with a cron: key. UTC always, with a 5-minute minimum granularity enforced by the runner.
  • AWS EventBridge / Scheduler — wrapped in cron(...) with a sixth year field and ? for one of day-of-month or day-of-week. See the AWS EventBridge guide for the full ruleset.
  • Most CI runners (GitLab, Jenkins, CircleCI) — each adds small dialect tweaks but builds on the same 5-field core.

Common mistakes when writing cron jobs

Commands don’t pick up your interactive shell. Cron runs commands with a minimal PATH and no ~/.bashrc, ~/.zshrc or login profile. Either use absolute paths (/usr/local/bin/python3 /opt/scripts/run.py) or set PATH= at the top of the crontab. The number-one reason a cron job “works on my terminal but not in cron” is environment.

Output goes to email by default — and email usually goes nowhere. Standard cron mails any stdout/stderr to the local mailbox. On modern systems with no mailer configured, the output is silently dropped. Always redirect: >> /var/log/myjob.log 2>&1.

Day-of-month and day-of-week interact weirdly. When both are specified (0 9 15 * 1) Unix cron treats it as OR — runs on the 15th of the month and every Monday, not the intersection. To get “Mondays at 9 AM”, leave day-of-month as *. AWS EventBridge sidesteps this by requiring ? for one of the two fields.

For ready-to-paste expressions covering specific intervals, see common cron schedules, or build a custom expression with the Cron Expression Builder.

Frequently asked questions

What is the difference between a cron job and a cron expression?
A **cron expression** is just the schedule — five space-separated fields like `*/5 * * * *`. A **cron job** is the full entry: the expression plus the command to run plus (on Unix) the user identity it runs as. The expression tells cron *when*; the job is *when + what*.
Do cron jobs run if my computer is asleep or off?
No — classic cron is a daemon that needs the machine running at the scheduled time. macOS uses launchd which can wake the system for some jobs; Linux uses anacron to "catch up" missed jobs after wake. Cloud schedulers like AWS EventBridge and Kubernetes CronJobs are independent of any single machine being on, which is why they're preferred for production schedules.
How do I create my first cron job on Linux?
Run `crontab -e` to open your user crontab in `$EDITOR`, add a line in the form `<schedule> <command>` (e.g. `0 9 * * 1 /usr/local/bin/weekly-report.sh`), save and exit. Verify with `crontab -l`. Output goes to mail by default — redirect with `>> /var/log/myjob.log 2>&1` to capture it.

Need a different schedule?

Build cron expressions for Unix, Kubernetes, AWS EventBridge and Quartz — with a human-readable description and the next 5 run times.

Open the Cron Expression Builder →

Related