Quick Answer
A cron job is a scheduled task on a Unix-based operating system, such as Linux or macOS, that runs a command or script automatically at specified times or intervals, without any manual action. It is managed through a configuration file called a crontab and is commonly used for automating backups, sending reports, clearing temporary files, or running any repetitive task on a schedule.
Where the Name Comes From
The word cron comes from the Greek word chronos, meaning time, reflecting its role as a time-based job scheduler. It has been a standard feature of Unix-like operating systems for decades, making it one of the oldest and most widely used scheduling tools in computing.
How a Cron Job Is Structured
A cron job is defined by a line in a crontab file, consisting of five time and date fields followed by the command to run. The five fields represent minute, hour, day of the month, month, and day of the week, each of which can be a specific value, a range, or an asterisk meaning every possible value for that field.
| Field | Allowed Values |
|---|---|
| Minute | 0 to 59 |
| Hour | 0 to 23 |
| Day of month | 1 to 31 |
| Month | 1 to 12 |
| Day of week | 0 to 6, where 0 represents Sunday |
Common Uses for Cron Jobs
- Running automated database or file backups overnight when system load is low
- Sending scheduled email reports or notifications at a set time each day or week
- Clearing temporary files, logs, or caches on a regular schedule to free up storage space
- Checking website or server uptime and triggering an alert if something is unresponsive
- Running data processing or synchronisation tasks between systems on a recurring basis
Editing a Crontab File
On most Unix-based systems, a user can view or edit their personal crontab using a terminal command that opens the file in a text editor. Each line added represents one scheduled job. It is worth noting that mistakes in a crontab, such as an incorrect schedule or a broken command, can cause a job to run at the wrong time or fail silently, so testing commands manually before scheduling them is good practice.
Cron Jobs vs Other Scheduling Methods
While cron is the traditional Unix scheduling tool, many modern applications and cloud platforms offer their own scheduling systems, sometimes built on top of cron itself, with added features like retry logic, monitoring dashboards, and easier configuration through a graphical interface rather than editing a text file directly. These are often preferred for complex or business-critical scheduled tasks, while raw cron remains popular for simpler server-level automation.
Common Mistakes When Setting Up Cron Jobs
- Assuming the server’s time zone matches your own, which can cause jobs to run at unexpected times
- Forgetting that cron jobs run with a limited environment, meaning some environment variables available in a normal terminal session may not be present
- Not redirecting command output to a log file, making it difficult to diagnose a job that silently fails
- Scheduling too many resource-intensive jobs at the same time, causing server performance issues
Related Reading
Automating your own workflow further? See our guide on web development best practices.
Frequently Asked Questions
Can cron jobs run on Windows?
Not natively, since cron is a Unix-based tool, though Windows has its own equivalent called Task Scheduler for similar automated scheduling.
How do I know if my cron job actually ran?
Redirecting the command’s output to a log file, or using a monitoring service, lets you confirm whether a job ran successfully or failed.
What does an asterisk mean in a cron schedule?
It means every possible value for that field, so an asterisk in the hour field means the job runs every hour.
Can I run a cron job every few minutes?
Yes, using a step value in the minute field, such as every five or ten minutes, rather than a single fixed minute.
Is cron still used with modern cloud platforms?
Yes, many cloud platforms either support cron syntax directly or offer their own scheduling tools built on similar underlying principles.
