Cron vs Anacron, what are the differences?

Alexis Clarembeau
3 min readAug 19, 2022

As a system administrator or a developer, you may have already asked yourself the question “how to implement recurring tasks on my system”. Indeed, this is a frequent task, which can be useful for you for many use cases (maintenance scripts, daily tasks, …).

Now, if you work on Linux, it is very likely that you have been confronted with two software: cron and anacron. As both software are very similar on paper, it could happen to confuse them or ask yourself which one to use.

In this article, we will try to explain the main differences between these two tools, to help you better choose the day you will have to choose between the two.

Cron

cron is a program that allows users of Unix systems to automatically run scripts, commands, or software at a pre-specified date and time, or on a pre-defined cycle.

The concept of this program originated in the Berkeley and AT&T Unix systems and was later streamlined by Paul Vixie. The original idea was to have a service that wakes up every minute, scans a set of files in a particular directory, and determines from that whether such and such shell commands should be executed in that time frame.

cron is a daemon, which in computer jargon means a program that runs in the background. The cron service (crond) thus waits until the time specified in the configuration file (which is called the crontab) and then performs the corresponding action and goes to sleep until the next event.

Anacron

anacron, on the other hand, is also a computer program that allows daily, weekly or monthly tasks to be executed on a Unix system.

Unlike cron, it does not assume that the machine is running continuously. As a result, it can be used on machines that are not running 24 hours a day, to monitor daily, weekly, or monthly tasks that are ordinarily monitored by cron.

Using cron, if the system is shut down when the task was scheduled, it will not run this time, and you will have to wait for the next occurrence to see the task run. anacron, when it starts, checks for each task whether it has been run in the last n days, where n is the periodicity defined for that task. If the answer is no, anacron runs the command for the task. If therefore, the machine was off at the exact time the task should have run to meet the n-day period, it is run the next time anacron starts.

Conclusion

Although very similar in principle, cron and anacron allow you to answer different use cases, depending on whether or not you need to catch up on jobs that should have run in the event of a service interruption on your machine (if you want to catch up on failed executions, you should prefer anacron).

About Us

As you can see, setting up recurring tasks can be complex. Depending on your use case, you’re going to need to set up machines with high availability to ensure that your tasks are executed correctly. However, there are also other alternatives. At Cronit, for example, we offer a system for managing, scheduling, and executing recurring tasks 100% online and without a server. Simply define your jobs using a web interface, and we take care of everything, so you have time to focus on the logic of your jobs, not their infrastructure

--

--