LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Learning cron : CentOS7 : anacron and cron (https://www.linuxquestions.org/questions/linux-newbie-8/learning-cron-centos7-anacron-and-cron-4175594192/)

fanoflq 11-24-2016 07:50 PM

Learning cron : CentOS7 : anacron and cron
 
Both anacron and cron are up, but in sleep at this point:

Code:

[user1@server1 cron.hourly]$ ps aux | grep -i anacron
root      4261  0.0  0.0 123308  740 ?        Ss  12:01  0:00 /usr/sbin/anacron -s
user1    5084  0.0  0.0 112648  948 pts/0    R+  12:24  0:00 grep --color=auto -i anacron
[user1@server1 cron.hourly]$ ps aux | grep -i crond
root      1331  0.0  0.1 126332  1660 ?        Ss  11:42  0:00 /usr/sbin/crond -n
user1    5089  0.0  0.0 112648  948 pts/0    R+  12:24  0:00 grep --color=auto -i crond

From man anacron page"
Code:

DESCRIPTION
      Anacron  is  used  to  execute  commands periodically, with a frequency
      specified in days.  Unlike cron(8), 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  reads  a  list  of jobs from the /etc/anacrontab configuration
      file (see anacrontab(5))
.  This file contains the  list  of  jobs  that
      Anacron  controls.  Each job entry specifies a period in days, a delay
      in minutes, a unique job identifier, and a shell command.

      For each job, Anacron checks whether this job has been executed in  the
      last  n  days, where n is the time period specified for that job.  If a
      job has not been executed in n days or more,  Anacron  runs  the  job's
      shell command, after waiting for the number of minutes specified as the
      delay parameter.

      After the command exits, Anacron records the date (excludes  the  hour)
      in  a  special timestamp file for that job, so it knows when to execute
      that job again.

And from man cron page:

Code:

DESCRIPTION
.......In case systemd is enabled, then  unit  file
      is  installed  into  /lib/systemd/system/crond.service  and  daemon  is
      started by systemctl start crond.service command.  It  returns  immedi‐
      ately,  thus, there is no need to need to start it with the '&' parame‐
      ter.

      Cron searches /var/spool/cron for crontab files which are  named  after
      accounts in /etc/passwd; The found crontabs are loaded into the memory.
      Cron also searches for /etc/anacrontab and any files in the /etc/cron.d
      directory,  which have a different format (see crontab(5)).  Cron exam‐
      ines all stored crontabs and checks each job to see if it needs  to  be
      run  in  the  current  minute.  When executing commands, any output is
      mailed to the owner of the crontab (or to the  user  specified  in  the
      MAILTO  environment  variable in the crontab, if such exists).  Any job
      output can also be sent to syslog by using the -s option.


Since cron and anacron also checks /etc/anacrontab,
Q1: How do they resolve not executing /etc/anacrontab twice?

Q2: I am not able to find how anacron was started using: systemctl --all.

How do I find out how anacron was started and by who?
man anacron did not help much.

Thanks.

michaelk 11-24-2016 09:31 PM

anacron is not a service and is started by cron.


https://www.certdepot.net/rhel7-how-...arted-anacron/

fanoflq 11-24-2016 09:50 PM

Quote:

Originally Posted by michaelk (Post 5634307)
anacron is not a service and is started by cron.


https://www.certdepot.net/rhel7-how-...arted-anacron/

Thank you.


All times are GMT -5. The time now is 08:21 AM.