I've been googling in vain to turn up a general explanation of how cron and anacron work together. The man pages are a bit too deep of a dive for me at this point.
I get confused because I add tasks to crontab, and that works, but when I delete them out of crontab, they still run under anacron. I see the tasks in /etc/cron.daily, but I am not sure how they got there. cron is running on my system always, but not anacron. In fact, I see anacron is started by cron!
Basically I'd like a user-level intro on how to add and remove tasks, since the easily googleable answers that tell you to edit crontab clearly are not complete. A link to a tutorial would be fine.
Both
cron
andanacron
are daemons that can schedule execution of recurring tasks to a certain point in time defined by the user.The main difference between
cron
andanacron
is that the former assumes that the system is running continuously. If your system is off and you have a job scheduled during this time, the job never gets executed.On the other hand
anacron
is 'anachronistic' and is designed for systems that are not running 24x7. For it to workanacron
uses time-stamped files to find out when the last time its commands were executed. It also maintains a file/etc/anacrontab
just likecron
does. In addition,cron.daily
runs anacron every day. Hence,anacron
can only run a job once a day, butcron
can run as often as every minute.From
man anacrontab
:This means, if a task is scheduled to be run daily and the computer was turned off during that time, when anacron is run, it can see that the task was last run more than 24 hours ago and execute the task correctly.
For example if you specify the following in
/etc/anacrontab
:and on the day when the
script.sh
job is supposed to executed, if the system is not running,anacron
will execute thescript.sh
15 minutes after the system comes back up.Few Reference: