Fedora Cron and Anacron Schedule Setup

This article assumes that you have the basic knowledge of cron and anacron. With the availability of both cron and anacron tools, different Linux distribution configures their schedule task differently.

For Red Hat Linux and Fedora system, there are also significant changes compared to the previous setup.

Before Fedora 10, the default crontab file is setup as follows:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

In the older version of Red Hat Linux and Fedora, anacron was setup to run during the system boot up and initialization process. A script file named as anacron can be found in /etc/rc.d/init.d, the directory that stores the system boot up script.

However, from Fedora 11 onwards, the cron jobs mentioned above are split between cron and anacron.

The default crontab file has no entries as shown below:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# .—————- minute (0 – 59)
# |  .————- hour (0 – 23)
# |  |  .———- day of month (1 – 31)
# |  |  |  .——- month (1 – 12) OR jan,feb,mar,apr …
# |  |  |  |  .—- day of week (0 – 6) (Sunday=0 or 7)  OR
#sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  command to be executed

So, where are the cron jobs’ configurations? First, all the daily, weekly and monthly scripts are configured under anacrontab and it is set to be run by anacron. The default anacrontab file is as follows:

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
1   65     cron.daily          nice run-parts /etc/cron.daily
7   70     cron.weekly         nice run-parts /etc/cron.weekly
@monthly 75 cron.monthly       nice run-parts /etc/cron.monthly

With anacron running all the scripts located in /etc/cron.daily, cron.weekly and cron.monthly. Cron is left with running the scripts in /etc/cron.hourly. The configuration of the hourly cron job is located at /etc/cron.d/0hourly. The default is as follows:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
01 * * * * root run-parts /etc/cron.hourly

Since anacron is not a daemon, this means that anacron need to be activate by scheduled scripts or command. In Fedora, a script file named “0anacron” is located at /etc/cron.hourly. This indicates that anacron is schedule to run on an hourly basis.

In conclusion, the cron daemon in Fedora now only run the script stored in /etc/cron.hourly which configuration is based on /etc/cron.d/0hourly. In the folder /etc/cron.hourly there is a script that runs anacron on an hourly basis. This anacron script then runs all other scripts in the daily, weekly and monthly folders.

Therefore, from Fedora 11 onwards you need to installed cron and anacron in order to have your system task scheduler running properly.

While this is a good arrangement, since most users do not turn on their PC 24×7, I agreed with some users’ suggestion that Fedora should include additional explanatory notes to explain the new configuration in the file crontab.

If you want to remove anacron and use cron exclusively, you need to use the old configuration of crontab and append to the crontab as shown below:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# .—————- minute (0 – 59)
# |  .————- hour (0 – 23)
# |  |  .———- day of month (1 – 31)
# |  |  |  .——- month (1 – 12) OR jan,feb,mar,apr …
# |  |  |  |  .—- day of week (0 – 6) (Sunday=0 or 7)  OR
#sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  command to be executed
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

It is not advisable to remove cron because anacron cannot run a task at a specific time.

End

Advertisements

Comments are closed.

%d bloggers like this: