Professional Documents
Culture Documents
Example)
Anacrontab Format
Just like how cron has /etc/crontab, anacron has
/etc/anacrontab.
/etc/anacrontab file has the anacron jobs mentioned in the
following format.
1 daily
7 weekly
30 monthly
# cat /var/spool/anacron/test.daily
20110507
Anacron Example
The following example executes the
/home/sathiya/backup.sh script once in every 7 days.
On the day when the backup.sh job is supposed to
executed, if the system is down for some reason, anacron
will execute the backup.sh script 15 minutes after the
system comes back up (without having to wait for another 7
days).
# cat /etc/anacrontab
7
15
test.daily
/bin/sh /home/sathiya/backup.sh
START_HOURS_RANGE and
RANDOM_DELAY
The above example indicates that the backup.sh script
should be executed every day, with a delay of 15 mins. i.e
When the laptop was started, executed it only after 15
minutes.
What happens when the laptop or desktop was not
shutdown? When does the job gets executed? This is
specified by the START_HOURS_RANGE environment
variable in the /etc/anacrontab file.
By default this is set to 3-22 in the file. This indicates the
time range from 3 a.m to 10 p.m.
# grep START /etc/anacrontab
START_HOURS_RANGE=3-22
Cron Vs Anacron
Cron and anacron has its own advantages and
disadvantages. Depending on your requirement, use one of
them.
Cron
Minimum granularity is minute (i.e
Jobs can be scheduled to be
executed every minute)
Cron job can be scheduled by any
normal user ( if not restricted by
super user )
Cron expects system to be running
24 x 7. If a job is scheduled, and
system is down during that time,
job is not executed.
Ideal for servers
Use cron when a job has to be
executed at a particular hour and
minute
Anacron
Minimum granularity is only in days
Anacron can be used only by super user ( but
there are workarounds to make it usable by
normal user )
Anacron doesnt expect system to be running
24 x 7. If a job is scheduled, and system is
down during that time, it start the jobs when
the system comes back up.
Ideal for desktops and laptops
Use anacron when a job has to be executed
irrespective of hour and minute