Cron Expression Generator

Cron Jobs Explained: Scheduling Tasks on a Server

📅 April 2026⏱ 8 min read✍️ ToolsBox

Cron is one of the most powerful and enduring tools in a server administrator's toolkit — and one of the most confusing for beginners. Whether you need to back up a database every night, send a weekly email, or run a data processing script every five minutes, cron is the standard way to schedule it on a Linux or Unix server. This guide explains everything you need to know.

What Is Cron?

Cron is a time-based job scheduler built into Unix and Linux operating systems. The name comes from the Greek word chronos (time). The cron daemon — a background process called crond — runs continuously and checks a configuration file called the crontab (cron table) every minute. When the current time matches a job's schedule, the daemon executes that job.

Cron is ideal for any task that needs to run automatically on a schedule:

  • Database backups (nightly at 2 AM)
  • Log rotation and cleanup (weekly)
  • Sending scheduled emails or reports (every Monday at 9 AM)
  • Updating cached data (every 15 minutes)
  • Running data import/export scripts (hourly)
  • Certificate renewals (twice daily — as certbot recommends)

Understanding the Crontab Format

Each line in a crontab file defines one scheduled job in this format:

* * * * * command-to-execute
│ │ │ │ │
│ │ │ │ └── Day of week (0–7, Sunday=0 or 7)
│ │ │ └──── Month (1–12)
│ │ └────── Day of month (1–31)
│ └──────── Hour (0–23)
└────────── Minute (0–59)

Each field can contain:

  • A specific value: 5 (exactly 5)
  • A wildcard: * (every possible value)
  • A range: 1-5 (values 1 through 5)
  • A step: */15 (every 15 units) or 0-30/10 (every 10 in the range 0–30)
  • A list: 1,3,5 (values 1, 3, and 5)

Common Cron Expression Examples

Here are practical cron expressions for the most common scheduling needs:

  • 0 2 * * * — Run at 2:00 AM every day
  • */5 * * * * — Run every 5 minutes
  • 0 9 * * 1 — Run at 9:00 AM every Monday
  • 0 0 1 * * — Run at midnight on the first of every month
  • 30 8 * * 1-5 — Run at 8:30 AM Monday through Friday (weekdays only)
  • 0 */6 * * * — Run every 6 hours (at 0:00, 6:00, 12:00, 18:00)
  • @daily — Shorthand for 0 0 * * * — run once per day at midnight
  • @weekly — Shorthand for 0 0 * * 0 — run once per week on Sunday
  • @reboot — Run once when the system starts up

How to Add a Cron Job

To add a cron job on Linux, edit your user's crontab file:

  1. Open the terminal and run crontab -e. This opens the crontab in your default editor.
  2. Add a new line with your schedule and command. Use absolute paths for both the command and any files it accesses: 0 2 * * * /usr/bin/php /var/www/html/backup.php
  3. Save the file and exit the editor. Cron picks up the changes automatically — no restart needed.
  4. Verify the job was saved: run crontab -l to list your current cron jobs.

For system-wide cron jobs (running as root), use sudo crontab -e or edit files in /etc/cron.d/, /etc/cron.daily/, /etc/cron.weekly/, or /etc/cron.monthly/.

Building Cron Expressions Without Memorising the Syntax

The five-field syntax is easy to get wrong, especially for complex schedules. Our Cron Expression Generator lets you build any cron schedule visually — choose the frequency, the specific times, and the tool generates the correct expression for you. It also explains existing expressions in plain English so you can verify what a schedule in your code actually means.

For example, paste in 0 */4 * * 1-5 and the tool will tell you: "At minute 0, every 4 hours, Monday through Friday." No mental parsing required.

Debugging Cron Jobs

Cron jobs run in a minimal shell environment without the environment variables your interactive session has. This is the most common source of "it works when I run it manually but not in cron" problems:

  • Use absolute paths: Instead of php script.php, use /usr/bin/php /home/user/script.php.
  • Set PATH in crontab: Add PATH=/usr/local/bin:/usr/bin:/bin at the top of your crontab.
  • Redirect output: Capture stdout and stderr with 0 2 * * * /path/to/script.sh >> /var/log/myjob.log 2>&1 to see what the job outputs.
  • Check the system log: On Ubuntu/Debian: grep CRON /var/log/syslog. On CentOS/RHEL: cat /var/log/cron.
  • Test the command manually: Run the exact command as the cron user to reproduce any errors.

Build cron expressions visually — free

No need to memorise the syntax — generate and explain any cron schedule instantly.
Open Cron Expression Generator →

Frequently Asked Questions

What is a cron job?

A cron job is a scheduled task that runs automatically at specified times on a Unix/Linux server. The cron daemon (background process) reads a file called the crontab and executes the listed commands at their scheduled times — even if no user is logged in.

What does */5 mean in a cron expression?

The */5 syntax means "every 5 units." In the minute field, */5 means "every 5 minutes" (at 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55). In the hour field, */2 would mean "every 2 hours."

How do I edit my crontab?

Run "crontab -e" in your terminal to open the crontab editor. This opens your user's crontab file in the default text editor (usually nano or vi). Add your cron job line, save, and exit. The cron daemon picks up the changes automatically.

Why is my cron job not running?

Common reasons: the cron daemon is not running (check with "systemctl status cron"); the command path is wrong (cron has a minimal PATH — use absolute paths); the script is not executable (run chmod +x); or there is a syntax error in the crontab. Check /var/log/syslog or /var/log/cron for error messages.

Back to Blog  |  Related tool: Cron Expression Generator