While cron is the classic standby to run routine tasks on a regular basis, it’s not quite as useful on systems (like laptops and desktops) that may not be powered on when the task is scheduled to run. Fortunately, Linux users have anacron to fill the gap left by cron.
Linux (like Unix) relies on cron to run certain tasks on a regular basis. Typically, a Linux system uses a series of directories (/etc/cron.daily, /etc/cron.hourly, and so on) to store scripts you want to be run at specific times. Precisely when they’re run is determined by /etc/crontab. Ordinary users and the system administrator can also create individual cron jobs. This mechanism is useful for running programs that perform routine maintenance — to prune /tmp, rotate log files, look for software updates, and so on.
Unfortunately, cron has an Achilles Heel: It can’t run if the computer is turned off. Although most servers run continuously, many computers, including most laptops and many desktop systems, don’t. These systems are often powered off more than they’re powered on to save energy. Unfortunately, many important cron jobs are routinely scheduled to run in the dead of night (usually between midnight and 6:00 am) to avoid conflicts with user tasks. This is precisely the time when laptops and desktops are most likely to be shut down. Hence, cron jobs don’t run and the results are log files growing out of control, increased clutter in /tmp, among other detrimental effects.
Fortunately, there’s armor for cron’s Achilles Heel: anacron. This utility, which ships with most Linux distributions, can run a program if it hasn’t run within a specified period of time. Configured appropriately, anacron can plug the hole left when cron doesn’t run late at night, by running your usual cron jobs when you power up a…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: