• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL : anacron basics (What is anacron and how to configure it)

By admin

What is anacron and how its different from cron?

Anacron is used to execute commands periodically, with a frequency specified in days. Unlike cron, it does not assume that the machine is running continuously. Hence, it can be used on machines that are not running 24 hours a day to control regular jobs as daily, weekly, and monthly jobs. Anacron tries to run the scheduled jobs as close as the system uptime permits.

anacron configuration file

/etc/anacrontab is the anacron configuration file. Below is a sample, unedited anacron file :

# cat /etc/anacrontab 
# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22

#period in days    delay in minutes   job-identifier   command
1	5	cron.daily		nice run-parts /etc/cron.daily
7	25	cron.weekly		nice run-parts /etc/cron.weekly
@monthly 45	cron.monthly		nice run-parts /etc/cron.monthly

Here :
1. period in days : specifies the frequency of execution of a job in days. This variable can be represented by an integer or a macro (@daily, @weekly, @monthly), where @daily denotes the same value as the integer 1, @weekly the same as 7, and @monthly specifies that the job is run once a month, independent on the length of the month.
2. delay in minutes: specifies the number of minutes anacron waits, if necessary, before executing a job. This variable is represented by an integer where 0 means no delay.
3. job-identifier: specifies a unique name of a job which is used in the log files.
4. command: specifies the command to execute. The command can either be a command such as ps -ef >> /tmp/processes or a command to execute a custom script.

The 3 lines at the end of the configuration files are system defined cron jobs.

1	5	cron.daily		nice run-parts /etc/cron.daily
7	25	cron.weekly		nice run-parts /etc/cron.weekly
@monthly 45	cron.monthly		nice run-parts /etc/cron.monthly

Rest of the variables are explained with an example below.

Example of anacron configuration

Let us check an example of configuring anacron. We are creating anacron job to run a script named “daily_job.sh” daily with a 35 min delay after the system comes up.

# cat /etc/anacrontab
RANDOM_DELAY=30
START_HOURS_RANGE=10-18
1       35      daily_job      sh /var/tmp/daily_job.sh

If the system is running then job will run as per START_HOURS_RANGE which is defined in /etc/anacrontab file. The START_HOURS_RANGE variable defines the range of hours in which the sheduled jobb is allowed to run. In our case it is 10 A.M. to 6 P.M. (10-18)

# grep -i START_HOURS_RANGE /etc/anacrontab  
START_HOURS_RANGE=10-18

The RANDOM_DELAY variable denotes the maximum number of minutes that will be added to the delay in minutes variable which is specified for each job. A RANDOM_DELAY set to 30 would therefore add, randomly, between 0 and 30 minutes to the delay in minutes for each job in that particular anacrontab. When set to 0, no random delay is added.

# grep -i RANDOM_DELAY /etc/anacrontab  
RANDOM_DELAY=30

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. How to Password Protect GRUB2 in Oracle Enterprise Linux 7
  2. CentOS / RHEL : Installing and Configuring ASMLib
  3. Linux OS Service ‘sshd’
  4. How to scan newly Assigned LUNs in Multipathd under CentOS / RHEL
  5. How to monitor the Mounting/Umounting of Mount Points Using Auditd on CentOS/RHEL 6,7
  6. –force V/s –nodeps : rpm command options to install or uninstall a package
  7. Beginners Guide to Linux Software Management with RPM
  8. How to find and delete files older than some particular time period in Linux
  9. How to Limit some User Memory Resources on CentOS/RHEL using cgroup
  10. CentOS / RHEL : How to adjust the telnet timeout (and how to disable it)

You May Also Like

Primary Sidebar

Recent Posts

  • What are different Oracle Database Vault Roles
  • Unable to export realm protected table using data pump
  • Beginners Guide to Oracle Database Vault
  • How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary