cron Daemon IV: Scheduling Processes
Scheduling Processes
Using anacron
Some distributions use anacron along with cron to automate the running of tasks. The two services working pretty much the same manner. The key difference is that cron assumes that your computer system will remain up and running 24 hours a day, 7 days a week. That’s fine for some systems, such as servers anddesktops, but not for others. For example, a notebook system is very likely to be off or asleep during certain periods of the day. If a system is not powered on when a scheduled cron job should run, it is skipped.
The anacron service attempts to work around this issue. If a job is scheduled in anacron, but
the system is off, then the missed job will automatically run when the system comes back up.
Just as cron uses the /etc/crontab file,
anacron uses the
/etc/anacrontab
file. This file uses the following fields:
period delay job-identifier command
The first field specifies the recurrence period (in days). For example, you could use any one of
the following values in this field:
• 1
The task recurs daily.
• 7
The task recurs weekly.
• 30
The task recurs monthly.
The second field specifies the delay (in minutes) anacron should wait before executing a
skipped job after the system starts up.
The third field contains the job identifier. This is the name that will be used for the job’s timestamp file and must be unique for each anacron job. This file is created in the
/var/spool/anacron
directory and contains a single line with a timestamp that indicates the last time the particular job
was run.
The fourth field specifies the command or script that should be run.
Consider the following example in which anacron is configured to run the /usr/bin/updatedb.sh
script once a day. If the system is down when the anacron job is supposed to run, the script will
be executed 30 minutes after the system comes back up.
openSUSE:/ # cat /etc/anacrontab
1 30 updatedbtime.log /usr/bin/updatedb.sh
Notice that this file does not specify the exact time when the job will run. This is configured
by the START_HOURS_RANGE variable in the /etc/anacrontab file. In the following example,
the start range is set to 3-22, which specifies a time range from 3 a.m.to 10 p.m.
openSUSE# cat /etc/anacrontab
...
START_HOURS_RANGE=3-22
It’s important to note that anacron also adds a random number of minutes to whatever value
you specified in the second field of the anacrontab file. The number of minutes that can be added is constrained by the RANDOM_DELAY variable within the /etc/anacrontab file. By default,this variable is set to a value of 45, which causes anacron to add a random number of minutes between 0 and 45 to the delay time in the anacrontab file. This is shown here:
openSUSE# cat /etc/anacrontab
...
RANDOM_DELAY=45
LX0-104 Exam Objectives (L)
No comments:
Post a Comment