Automation is at the heart of modern system administration. On Linux and Unix-like systems, two of the most common tools for scheduling repetitive tasks are Cron and Anacron. At first glance, they seem very similar: both allow you to schedule jobs such as backups, log rotations, or cleanup scripts. But they differ significantly in how and when they execute those jobs.
Understanding these differences—and how to monitor jobs once they are scheduled—is critical for anyone who wants to keep systems running smoothly.
What is Cron?
Cron is a time-based job scheduler that has been a cornerstone of Unix and Linux systems for decades. It uses a background service called the cron daemon (crond
) to check configuration files (called crontabs) for scheduled tasks.
Each job in a crontab follows a simple syntax to define when it should run, down to the exact minute. Cron is designed for environments where systems are running continuously, such as production servers.
Key Features of Cron
- Executes tasks at specific, precise times (e.g., 3:15 AM daily).
- Can run jobs every minute, hour, day, week, or month.
- If the system is off at the scheduled time, the job will be missed. Cron does not automatically “make up” for downtime.
- Supports per-user crontabs (via
crontab -e
) and a system-wide crontab (/etc/crontab
).
Example of a Cron Job
0 2 * * * /usr/local/bin/backup.sh
This will run the backup script every day at 2:00 AM sharp.
What is Anacron?
Anacron was created to solve a limitation of Cron: what happens if your computer is off when the job is supposed to run? For servers that run 24/7, this isn’t a problem. But for laptops, desktops, or any machine that isn’t always powered on, Cron can skip important jobs.
Anacron ensures that jobs are eventually executed, even if they were missed due to downtime. It doesn’t work with per-minute precision like Cron; instead, it handles jobs at daily, weekly, or monthly intervals.
Key Features of Anacron
- Ensures scheduled jobs are run eventually, not skipped.
- Ideal for machines that are not running all the time.
- Jobs are configured in
/etc/anacrontab
. - Jobs can be delayed after startup to avoid slowing down boot.
Example of an Anacron Job
1 10 backup.daily /usr/local/bin/backup.sh
This means:
- Run the job once every 1 day.
- Wait 10 minutes after boot before running it.
- Identify this job as
backup.daily
.
So, even if the computer was turned off at 2 AM, Anacron will still run the backup when the system starts again.
Cron vs. Anacron
Although they serve similar purposes, Cron and Anacron differ in important ways:
Feature | Cron | Anacron |
---|---|---|
Scheduling | Minute, hour, day, month | Daily, weekly, monthly only |
Precision | Exact timing | Flexible (runs later if missed) |
Missed Jobs | Missed if system is off | Executes after boot if missed |
Best For | Servers running 24/7 | Laptops, desktops, non-24/7 PCs |
Configuration File | crontab , /etc/crontab | /etc/anacrontab |
In fact, many modern Linux systems use both together. Cron handles precise jobs, while Anacron ensures essential periodic jobs are not skipped.
Cron Job Monitoring
Scheduling jobs is only half the story—monitoring them is equally important. Without proper monitoring, you may not know if a backup script failed or a cleanup job never ran.
There are a few ways to monitor Cron jobs:
- Log Monitoring: By default, Cron logs to
/var/log/cron
or/var/log/syslog
depending on the distribution. Reviewing these logs can confirm whether jobs ran successfully. - Email Alerts: Cron can send the output of a job to the local mail of the user. By setting the
MAILTO
variable in a crontab, you can receive email notifications whenever a job runs (or fails). - External Monitoring Tools: Services like ClouDNS, Cronitor, Healthchecks.io, or Dead Man’s Snitch provide more advanced monitoring. They work by requiring your Cron job to “check in” with the monitoring service each time it runs. If a job doesn’t report back on time, you’ll receive alerts via email, Slack, or other channels.
System Monitoring Beyond Cron
While Cron job monitoring is essential, it only covers the tasks you explicitly schedule. For broader visibility into your system’s health and performance, you may also want a system monitoring service.
One popular option is Nagios, an open-source monitoring tool that can track system metrics, network status, and application availability. Unlike Cron-focused monitoring tools, Nagios provides:
- Alerts for CPU, memory, and disk usage.
- Service uptime monitoring (web servers, databases, etc.).
- Notification integration with email, SMS, or chat systems.
- A dashboard to visualize system health across multiple servers.
This makes Nagios (and similar tools like Zabbix or Prometheus) a valuable complement to Cron monitoring. While Cronitor tells you if your scheduled task ran, Nagios can tell you if your system is under strain, a process crashed, or a network link failed.
When to Use Cron, Anacron, and Monitoring
- Use Cron if you need precision and your system is always running.
- Use Anacron if your system is not always powered on, but you want to guarantee jobs still run eventually.
- Use Monitoring to ensure you actually know whether scheduled tasks succeeded and to keep an eye on overall system health.
Together, Cron, Anacron, and monitoring tools form a reliable automation and maintenance strategy for Linux and Unix environments.
Final Thoughts
Cron and Anacron are both indispensable for scheduling jobs, but they solve slightly different problems:
- Cron is about running jobs exactly on schedule.
- Anacron is about ensuring jobs eventually run, even if a system was off.
Adding monitoring—whether with Cron-specific tools like Cronitor or full system monitoring platforms like Nagios—completes the picture by providing visibility and alerts. That way, you don’t just schedule jobs—you know they actually ran and succeeded.