What is Cron?
Learn the fundamentals of cron, the time-based job scheduler in Unix-like operating systems.
Quick Summary: Cron is a time-based job scheduler that runs commands automatically at specified times. Think of it as your computer's alarm clock for running scripts and programs.
Definition
Cron (short for "chronos" - time in Greek) is a time-based job scheduler found in Unix-like operating systems including Linux, macOS, and FreeBSD. It enables users to schedule commands or scripts to run automatically at specified dates, times, or intervals.
The cron daemon (crond) runs continuously in the background and executes scheduled tasks called "cron jobs" based on the configuration in crontab files.
How Cron Works
The Cron Process:
- Cron Daemon Starts: When the system boots, the cron daemon starts automatically
- Reads Crontab Files: Cron reads scheduled jobs from various crontab files
- Checks Schedule: Every minute, cron checks if any jobs should run
- Executes Jobs: When a job's time matches, cron executes the command
- Logs Results: Output and errors are typically logged or emailed
Common Use Cases
System Administration
- • System backups
- • Log rotation
- • System updates
- • Disk cleanup
Application Tasks
- • Database maintenance
- • Email notifications
- • Data processing
- • Cache clearing
Development
- • Automated testing
- • Code deployment
- • Performance monitoring
- • Health checks
Business Operations
- • Report generation
- • Data synchronization
- • Inventory updates
- • Automated workflows
Basic Example
Here's a simple example of a cron job that backs up a database every day at 2 AM:
0 2 * * * /usr/local/bin/backup-database.sh
Breakdown: 0 (minute 0) 2 (hour 2) * (any day) * (any month) * (any day of week) followed by the command to execute.
Cron vs Other Schedulers
| Scheduler | Platform | Best For |
|---|---|---|
| Cron | Unix/Linux/macOS | System-level automation |
| Task Scheduler | Windows | Windows automation |
| Systemd Timers | Modern Linux | Service management |
| Kubernetes CronJobs | Container orchestration | Containerized applications |
Key Advantages of Cron
- ✅ Reliable: Decades of proven stability in production
- ✅ Lightweight: Minimal system resource usage
- ✅ Universal: Available on virtually all Unix-like systems
- ✅ Simple: Easy to understand and configure
- ✅ Flexible: Supports complex scheduling patterns
Next Steps
Now that you understand what cron is, learn how to create and manage cron jobs: