What is Cron?
Cron is a time-based job scheduler in Unix-like operating systems that enables users to schedule commands or scripts to run automatically at specified intervals. It uses a special syntax called cron expression to define when tasks should execute.
Quick Facts
| Full Name | Cron Job Scheduler |
|---|---|
| Created | 1979 by Ken Thompson |
| Specification | Official Specification |
How It Works
Cron was originally written by Ken Thompson for Version 7 Unix in 1979. The name comes from the Greek word 'chronos' meaning time. A cron expression consists of five or six fields representing minute, hour, day of month, month, day of week, and optionally year. Each field can contain specific values, ranges, lists, or special characters like asterisk (*) for 'any value'. Cron is fundamental to system administration for tasks like log rotation, backups, and scheduled maintenance. Cloud platforms offer managed cron services: AWS EventBridge (formerly CloudWatch Events), Google Cloud Scheduler, and Azure Logic Apps. These services provide reliability, monitoring, and integration with serverless functions, eliminating the need to manage cron on individual servers.
Key Characteristics
- Uses five or six field expression syntax (minute, hour, day, month, weekday)
- Supports special characters: * (any), , (list), - (range), / (step)
- Runs in the background as a daemon process
- Each user can have their own crontab file
- Expressions are evaluated in the system's local timezone
- Supports @yearly, @monthly, @weekly, @daily, @hourly shortcuts
Common Use Cases
- Scheduling automated backups
- Running periodic system maintenance tasks
- Sending scheduled reports and notifications
- Log rotation and cleanup
- Triggering CI/CD pipelines at specific times
Example
Loading code...Frequently Asked Questions
What does the asterisk (*) mean in a cron expression?
The asterisk (*) in a cron expression means 'every' or 'any value' for that field. For example, * in the hour field means 'every hour', and * * * * * means the job runs every minute.
How do I run a cron job every 5 minutes?
To run a cron job every 5 minutes, use the expression */5 * * * *. The /5 after the asterisk in the minute field means 'every 5 minutes' throughout the hour.
What is the difference between crontab and cron?
Cron is the daemon (background service) that executes scheduled tasks. Crontab (cron table) is the configuration file where you define the scheduled jobs. The crontab command is used to edit this file.
How do I schedule a job to run on weekdays only?
To run a job on weekdays only, use 1-5 in the day-of-week field (the fifth field). For example, 0 9 * * 1-5 runs at 9:00 AM Monday through Friday.
Why is my cron job not running as expected?
Common reasons include: incorrect cron syntax, wrong timezone settings, missing environment variables, permission issues, or the cron daemon not running. Check system logs (/var/log/cron or /var/log/syslog) for debugging.