Understanding Cron vs Anacron: Which Scheduler Fits Your Needs?
Published:
Scheduling tasks on Linux is essential for automating system maintenance, backups, or repetitive jobs. Two popular tools for this are Cron and Anacron. While they might seem similar, they serve different purposes and are optimized for different environments. Let’s break it down.
What is Cron?
Cron is a time-based job scheduler in Unix-like systems. It allows users to schedule tasks (called cron jobs) to run at specific intervals — every minute, hour, day, or month.
- Configuration: Jobs are defined in the crontab file.
- Use Case: Ideal for servers or machines that run continuously.
Example cron job:
# Run a backup script every day at 2 AM
0 2 * * * /usr/local/bin/backup.sh
Key Points About Cron:
- Jobs run only when the system is on.
- Precise scheduling down to the minute.
- Lightweight and widely used on servers.
What is Anacron?
Anacron is a scheduler designed for machines that do not run 24/7, such as laptops or desktops. Unlike Cron, Anacron guarantees that tasks are executed even if the system was off at the scheduled time.
- Configuration: Jobs are defined in /etc/anacrontab.
- Use Case: Perfect for periodic jobs on machines that may be offline when the task is supposed to run.
Example Anacron job:
# Run the backup job daily, retry if missed
1 5 backup /usr/local/bin/backup.sh
Key Points About Anacron:
- Jobs run after boot if they were missed.
- Minimum interval is 1 day (does not handle minute/hour-level scheduling).
- Adds reliability for non-continuous systems.
