Tutorial7 min read

How to Build a Cron Job Schedule: A Complete Guide with Examples

Cron syntax is compact but cryptic. Learn how the five fields work, common patterns for scheduling tasks daily, weekly, or at specific intervals, and how to build schedules without memorizing the syntax.

Cron is one of the oldest and most reliable task scheduling tools in computing, and the syntax hasn't changed in decades. The problem is those five fields look like a puzzle the first time you see them. Once you understand the structure, building any schedule becomes straightforward.

What Is Cron?

Cron is a time-based job scheduler built into Unix-like operating systems. It runs commands or scripts at specified times or intervals — automatically, in the background, without human intervention.

Common uses:

  • Nightly database backups
  • Hourly log rotation
  • Daily email reports
  • Weekly cleanup jobs
  • Minute-by-minute health checks

Cron jobs are configured in a file called a crontab (cron table). Each line is one scheduled job.

The Five-Field Syntax

Every cron expression consists of five time fields followed by the command to run:

┌─── minute (0–59)
│  ┌─── hour (0–23)
│  │  ┌─── day of month (1–31)
│  │  │  ┌─── month (1–12)
│  │  │  │  ┌─── day of week (0–6, 0=Sunday)
│  │  │  │  │
*  *  *  *  *  command-to-run

Each field can contain:

Value Meaning Example
* Any / every * * * * * = every minute
Number Specific value 30 14 = 2:30 PM
a-b Range 1-5 = Monday through Friday
*/n Every n units */15 = every 15 minutes
a,b,c List 1,15,30 = at minutes 1, 15, and 30

Common Schedules with Examples

Every minute

* * * * * /path/to/script.sh

Rarely useful in production — every minute is a lot. Good for testing.

Every 15 minutes

*/15 * * * * /path/to/script.sh

Runs at :00, :15, :30, :45 of every hour.

Once per hour (on the hour)

0 * * * * /path/to/script.sh

The 0 in the minute field means it runs exactly on the hour.

Every day at midnight

0 0 * * * /path/to/script.sh

Or at 6 AM:

0 6 * * * /path/to/script.sh

Every weekday at 9 AM

0 9 * * 1-5 /path/to/script.sh

1-5 in the day-of-week field means Monday (1) through Friday (5).

Every Monday at 8 AM

0 8 * * 1 /path/to/script.sh

First day of every month at midnight

0 0 1 * * /path/to/script.sh

Every quarter (January, April, July, October) on the 1st

0 0 1 1,4,7,10 * /path/to/script.sh

Twice a day (noon and midnight)

0 0,12 * * * /path/to/script.sh

Special Strings (Shortcuts)

Most modern cron implementations accept convenient shorthand strings:

String Equivalent Meaning
@yearly 0 0 1 1 * Once a year, January 1st at midnight
@monthly 0 0 1 * * First day of every month at midnight
@weekly 0 0 * * 0 Every Sunday at midnight
@daily 0 0 * * * Every day at midnight
@hourly 0 * * * * Every hour
@reboot Once, at system startup

Building Cron Expressions Without Memorizing Syntax

Use DevZone's Cron Builder to construct schedules visually — select the frequency, days, and times without memorizing the field order. The tool generates the correct cron expression and explains what it means in plain English.

For example, "every Monday and Wednesday at 9 AM" becomes:

0 9 * * 1,3

How to Manage Crontabs

View your current crontab:

crontab -l

Edit your crontab:

crontab -e

This opens your crontab in your default editor. Add one job per line.

Remove your crontab:

crontab -r

System-wide crontabs live in /etc/crontab and /etc/cron.d/. These have an extra username field:

0 6 * * * root /usr/bin/backup.sh

Cron and Timezones

Cron runs in the system timezone — usually UTC on servers. If you schedule 0 9 * * * intending 9 AM New York time, it will run at 9 AM UTC (4 or 5 AM New York time, depending on daylight saving).

Always specify your cron times in the server's timezone, or set TZ in your crontab (supported on most modern systems):

TZ=America/New_York
0 9 * * * /path/to/script.sh

Handling Output and Errors

By default, cron emails the output of each job to the system user. In most server environments, this goes nowhere. To capture output:

Log to a file:

0 6 * * * /path/to/script.sh >> /var/log/backup.log 2>&1

>> appends stdout. 2>&1 redirects stderr to stdout (so errors also go to the log).

Suppress all output (use with caution):

0 6 * * * /path/to/script.sh > /dev/null 2>&1

Only do this if you're confident the script handles its own error logging.

FAQ

Why isn't my cron job running?

Common causes:

  1. Path issues — cron runs with a minimal PATH. Use absolute paths for commands (/usr/bin/python3 not python3).
  2. Wrong timezone — verify the server's timezone with date and adjust your schedule accordingly.
  3. File permissions — the script must be executable: chmod +x /path/to/script.sh.
  4. Syntax error — test with crontab -l and verify the format.
  5. Output swallowed — add logging to confirm the script ran.

Can cron run more frequently than every minute?

No. One minute is the minimum interval for standard cron. For sub-minute scheduling, use a different tool: a while loop with sleep in a long-running process, or a purpose-built scheduler like systemd timers.

What's the difference between cron and systemd timers?

Systemd timers are the modern alternative on Linux systems. They offer better logging (via journald), dependencies, and more flexible time specifications. Cron is more portable and available on non-systemd systems.

How do I run a cron job in a Docker container?

Install cron (apt-get install -y cron), add your crontab, start the cron daemon (cron), and keep it running. Alternatively, use Kubernetes CronJobs or a platform-specific scheduler to avoid running cron inside containers.

Try the tools