ToolsCourt
Cron ToolsWhat is a Cron Job?
📖 Beginner Guide10 min read

What is a Cron Job?

A cron job is an automated task scheduled to run at fixed times or intervals on a server — without any human involvement. It's one of the oldest and most reliable ways to automate repetitive work in software development. This guide covers everything: what cron jobs are, how cron expressions work, real-world use cases, platform differences, and common mistakes.

📋 Table of Contents
  1. What is a cron job?
  2. How does cron work?
  3. What is a cron expression?
  4. Interactive field explorer
  5. Real-world use cases
  6. Cron across platforms
  7. Common mistakes
  8. Free cron job generator

What is a Cron Job?

A cron job is a scheduled task that a Unix or Linux server runs automatically at a defined time. The word "cron" comes from Kronos, the Greek personification of time — via Ken Thompson's implementation of the Unix scheduler in 1975. The scheduler itself is called the cron daemon (crond), a background process that reads a crontab (cron table) file and fires commands at the right moment.

Think of a cron job as a programmable alarm clock for your server. Instead of ringing a bell, it runs a script, sends an email, backs up a database, or does anything else you'd normally have to do manually. Once configured, it just runs — indefinitely, on schedule, with no human needed.

Simple example: nightly database backup
# This line in crontab runs /scripts/backup.sh every night at 2:00 AM
0 2 * * * /scripts/backup.sh

# ↑     ↑  ↑  ↑  ↑
# min  hr dom mon dow

How Does Cron Work?

Every minute, the crond daemon wakes up, reads all the crontab files on the system, and checks whether any scheduled job matches the current time. If there's a match, it spawns a child process and runs the command. The daemon then goes back to sleep until the next minute.

1
Cron daemon starts
crond runs as a background process, started automatically at boot via systemd or init.
2
Reads crontab files
Every minute it reads /etc/crontab, /etc/cron.d/, and each user's personal crontab.
3
Checks current time
Compares current minute/hour/day/month/weekday against every cron expression.
4
Runs matching jobs
For each match, spawns a subprocess to execute the command in a minimal shell environment.
⚠️ Cron's minimal environment: Cron runs with a stripped-down environment — it doesn't load your .bashrc or .profile. Commands that work in your terminal may fail in cron because PATH doesn't include /usr/local/bin or your home directory binaries. Always use absolute paths in cron scripts.

What is a Cron Expression?

A cron expression is a string of 5 space-separated fields that defines the schedule. Each field represents a unit of time. The fields are, in order: minute, hour, day-of-month, month, day-of-week.

0
Minute
9
Hour
*
Day/Month
*
Month
1-5
Day/Week
→ Runs at 9:00 AM every weekday (Monday–Friday)
SymbolMeaningExampleResult
*Any value (wildcard)* in HourEvery hour
*/nEvery nth value*/5 in MinuteEvery 5 minutes
a-bRange from a to b1-5 in Day/WeekMonday to Friday
a,b,cSpecific values1,3,5 in Day/WeekMon, Wed, Fri
nExact value9 in HourAt 9:00 AM (of current schedule)

Interactive: Explore Common Cron Schedules

Click any schedule below to see how the 5 fields map to a real-world use case.

0
Minute
2
Hour
*
Day/Month
*
Month
*
Day/Week
Database backups, log rotation

Real-World Cron Job Use Cases

Cron jobs are used everywhere in production systems. Here are the most common use cases developers rely on:

💾
Database backups
Run pg_dump or mysqldump nightly at low-traffic hours — typically 2–4am — to create automated database snapshots without manual intervention.
📧
Email digests
Aggregate activity and send a daily or weekly summary email to users. The cron job queries the database and triggers the mailer at a fixed time.
🗑️
Log rotation & cleanup
Delete or archive old log files, expired sessions, or temporary files on a schedule before they consume disk space.
🔄
Data sync & ETL
Pull data from external APIs, transform it, and load it into your database. Common for syncing CRMs, payment records, or analytics data.
📊
Report generation
Pre-compute expensive reports (sales summaries, user analytics) and store them so dashboards load instantly instead of calculating on demand.
🏥
Health checks
Ping your own endpoints every minute and alert if they're down — a simple uptime monitor you can run from any server with a crontab.
🔔
Notifications & alerts
Send scheduled reminders, subscription renewal warnings, overdue invoice alerts, or appointment reminders at the right time.
🧹
Cache invalidation
Clear or refresh Redis/Memcached caches on a schedule to prevent stale data accumulating without manual cache-bust deploys.

5 Common Cron Job Mistakes (and How to Fix Them)

1
Not using absolute paths
❌ Wrong
python backup.py
✅ Correct
/usr/bin/python3 /home/ubuntu/scripts/backup.py
Cron runs with a minimal PATH. Commands like python, node, or npm may not be found. Always use full paths — run `which python3` to find the absolute path.
2
Wrong timezone assumption
❌ Wrong
0 9 * * * (expecting 9am IST)
✅ Correct
30 3 * * * (9am IST = 3:30am UTC)
Linux crontab uses the server's system timezone. Cloud platforms like AWS EventBridge and GitHub Actions use UTC. Always confirm the server timezone with `timedatectl`.
3
Ignoring cron output
❌ Wrong
0 2 * * * /scripts/backup.sh
✅ Correct
0 2 * * * /scripts/backup.sh >> /var/log/backup.log 2>&1
By default, cron emails output to the system user — which nobody reads. Redirect stdout and stderr to a log file so you can debug failures.
4
Overlapping jobs
❌ Wrong
*/1 * * * * slow-task.sh (task takes 3 min)
✅ Correct
Use a lock file: flock -n /tmp/task.lock slow-task.sh
If a cron job takes longer than its interval, multiple instances pile up. Use flock or a PID file to ensure only one instance runs at a time.
5
Forgetting to test the script standalone first
❌ Wrong
Adding untested scripts to crontab
✅ Correct
Run /scripts/backup.sh manually as the cron user first
Test scripts by running them manually as the same user cron will use. Environment variables, permissions, and working directories may differ from your terminal session.

Free Cron Job Generator

Now that you understand how cron jobs work, use our free cron expression builder to create any schedule visually — no syntax memorisation needed. Get plain-English confirmation, next run times, and copy-ready code for your platform.

Cron Job Generator & Expression Builder
Visual builder · Plain-English output · Next 8 run times · Code for 7 platforms
Open Generator →

Continue Learning About Cron

📝
Guide
What is a Cron Expression?
💡
Reference
100 Cron Expression Examples
🐧
Tool
Linux Crontab Generator
☁️
Tool
AWS EventBridge Cron Builder
🛡️
Guide
Why Cron Jobs Fail Silently
Guide
Avoid CPU Overload with Cron