4

I've understood that the entries in /etc/cron.d/ are executed automatically. But I have also found these in /etc/

/etc/cron.daily/
/etc/cron.hourly/
/etc/cron.monthly/
/etc/cron.weekly/

In /etc/cron.d/ I found 0hourly which has this content:

01 * * * * root run-parts /etc/cron.hourly

There are no files called *daily, *monthly or *weekly.

Does this mean that if I add a script in /etc/cron.hourly it will get executed automatically? And that this will NOT happen for scripts in /etc/cron.daily, /etc/cron.monthly/ and /etc/cron.weekly/?

EDIT:

My /etc/crontab is empty, except for initializing the variables SHELL, PATH and MAILTO.

In /etc/cron.hourly/ I found the script 0anacron which seems to check if cron.daily have been run today or not. I also found /etc/anacron which contains this:

# /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

I guess it gave me some reading to do. Especially anacron(8) and anacrontab(5).

  • What does your /etc/crontab contain? – muru Jul 8 at 5:45
  • @muru It initializes the variables SHELL, PATH and MAILTO but nothing more. – klutt Jul 8 at 5:47
  • the only way to know for sure is to put a job in there and see if it actually runs or not ;-) – frostschutz Jul 8 at 5:54
5

It seems CentOS is like Ubuntu in this aspect, just configured slightly differently. Ubuntu uses anacron to run the daily/weekly/monthly jobs, and they're configured in /etc/crontab and /etc/anacrontab.

With CentOS, first we have:

# cat /etc/cron.hourly/0anacron
#!/bin/sh
# Check whether 0anacron was run today already
if test -r /var/spool/anacron/cron.daily; then
    day=`cat /var/spool/anacron/cron.daily`
fi
if [ `date +%Y%m%d` = "$day" ]; then
    exit 0;
fi

# Do not run jobs when on battery power
if test -x /usr/bin/on_ac_power; then
    /usr/bin/on_ac_power >/dev/null 2>&1
    if test $? -eq 1; then
    exit 0
    fi
fi
/usr/sbin/anacron -s

which checks/runs anacron once a day, and then:

# 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

where the daily, weekly and monthly crontabs are configured.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.