255

When do entries in cron.daily (and .weekly and .hourly) run, and is it configurable?

I haven't found a definitive answer to this, and am hoping there is one.

I'm running RHEL5 and CentOS 4, but for other distros/platforms would be great, too.

5
  • 2
    On NetBSD, the times for the daily,weekly, monthly cronjobs are set in root's crontab.
    – hd1
    Nov 17, 2014 at 1:05
  • This question would be more useful if the question was edited to be more generic. At the very least make the question generic for any versions of redhat, centos distros instead of only for versions 4 and 5 (which are not widely used and are "end of production" (similar to end of life). Jan 1, 2018 at 17:53
  • 1
    @TrevorBoydSmith - this question was asked nearly 8 years ago. Feel free to ask one updated for newer versions. But RHEL 6 didn't even exist in April 2010: access.redhat.com/articles/3078#RHEL6
    – warren
    Jan 4, 2018 at 16:04
  • @warren my intent is not to criticize but just improve the question and stackoverflow in general. (i understand that RHEL 6 didn't exist when the question was asked. because the question has soo many upvotes now it would be nice to have it more generic.) Jan 4, 2018 at 16:16
  • @TrevorBoydSmith .. there is an answer for CentOS/RHEL 6 already :) ...I'd be happy to approve good edits from you if you have some ideas. Go ahead and make suggested edits to the question that you've thought of
    – warren
    Jan 4, 2018 at 18:13

10 Answers 10

196

For the distributions you mention:

On CentOS 5.4 (Should be same for RHEL5)

grep run-parts /etc/crontab

01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

So cron.daily runs at 04:02am.

Same on CentOS 4.8

5
  • 2
    Is there any reason behind this? I can only assume it'd be the quietest time on the server. May 13, 2010 at 14:55
  • @ what time it runs in ubuntu? can you please tell how i can check it? i am not able to understand the command output Jan 2, 2016 at 11:16
  • 1
    @NarendraJaggi the "run-parts" command means "run everything in this folder". The cron.daily, etc. folders work because there is a cron job to execute run-parts on these directories. So grep run-parts /etc/crontab just finds the instructions on when run-parts is called for each of these directories. Jan 21, 2016 at 15:57
  • 6
    This is no longer valid answer for CentOS 6 or higher, scroll down for more.
    – lzap
    Oct 24, 2016 at 7:53
  • 1
    cant find it in /etc/crontab on CO 7
    – snh_nl
    Sep 1, 2020 at 15:40
92

From the man page:

 Cron also searches for /etc/anacrontab

/etc/anacrontab in my system (Fedora 12) :

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

See also man anacrontab

6
  • 9
    This is the case with CentOS 6. Thanks.
    – brandeded
    Jul 22, 2013 at 15:59
  • 4
    That means 5am every "1" days?. Sorry, but this answers nothing.
    – elysch
    May 13, 2016 at 16:50
  • 3
    @elysch Let me repeat the last line of my answer: See also "man anacrontab"
    – leonbloy
    May 13, 2016 at 17:53
  • 3
    Good explanation of anacron here. Basically, anacron has no fixed start time, but rather will start the process based on when the last process ran, with a specified delay. If the machine is off when the process should have ran, then it will start the process when the machine comes back up, after the specified delay (barring no special ranges + random delay, see answer by @spechal ). Jul 14, 2016 at 17:40
  • 3
    @mbrownnyc and also CentOS-7 too Jan 1, 2018 at 17:30
53

For CentOS 6, you need to grep /etc/anacrontab and the answer varies if the server/laptop/dekstop/etc has been turned off or not.

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

So, between the hours of 3AM and 10PM** (after reboot and after the machine has been up for 5 minutes^^), run /etc/cron.daily. If there is no reboot, the job should run at 3:05AM++.

** As defined by START_HOURS_RANGE
^^ As defined by FIELD_TWO (i.e. the 5 after the 1 in the cron.daily line)
++ plus a random time between 0 and 45 minutes as defined by RANDOM_DELAY

Reference: http://linux.die.net/man/5/anacrontab

18

For SuSE systems (specifically SLES 11.1 and openSuSE 10.3) the daily run time of the /etc/cron.daily scripts is controlled by the value of the DAILY_TIME variable set in the /etc/sysconfig/cron file.

If the DAILY_TIME variable is not set, it defaults to: (time of last boot + 15 minutes).

2
  • thx a lot! SuSE is rather opaque to me and I appreciate your answer.
    – dr0i
    Aug 2, 2016 at 8:18
  • Same with OpenSUSE - and the default is "", ie. a quarter after the last boot. This approach is suitable for desktop computers, which tend to be turned off when not needed.
    – Jasio
    Dec 17, 2020 at 8:25
14

On Ubuntu, you'll find a file /etc/crontab, from where this is configured. I guess it is something similar on RH and Centos.

3
  • 3
    This is the right file for Ubuntu Lucid 10.04 LTS. My default setting is 6:25am for cron.daily.
    – geekQ
    Aug 8, 2011 at 13:46
  • Still set as 6:25 am on Ubuntu 15.04. But I notice that cron must insert some randomness in the time it starts the jobs. Looking at the timestamps of the files my daily job creates, I see on some days it runs as early as 6:26, and on others as late as 8:04 am.
    – Stéphane
    May 6, 2015 at 10:51
  • 1
    Still set at 6:25am on Ubuntu 16.04 - Hourly at 17 minutes past hour. Daily at 6:25 am. Weekly at 6:47 am Saturday. Monthly at 6:52 am first day of month. Mar 1, 2017 at 11:47
6

CentOS6.x/RedHat6.x installs by default the package cronie-anacron. You have to:

yum install cronie-noanacron

yum erase cronie-anacron

Then you now have /etc/cron.d/dailyjobs to configure the best schedule time for your daily, weekly and monthly jobs.

2
  • 3
    If anacron is installed, couldn't you just edit /etc/anacrontab as per other comments here instead of uninstalling it? Feb 21, 2013 at 20:18
  • 1
    @cincodenada That's not what Daniel Stantos is suggesting. May 14, 2013 at 16:28
5

I use Slackware (14.0), and did not have /etc/crontab. Also, anacron is not part of the distribution.

The solution on my system was as simple as running crontab -l as root:

root@flea:~# crontab -l
# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null.  We'll do this here since these jobs should run
# properly on a newly installed system.  If a script fails, run-parts will
# mail a notice to root.
#
# Run the hourly, daily, weekly, and monthly cron jobs.
# Jobs that need different timing may be entered into the crontab as before,
# but most really don't need greater granularity than this.  If the exact
# times of the hourly, daily, weekly, and monthly cron jobs do not suit your
# needs, feel free to adjust them.
#
# Run hourly cron jobs at 47 minutes after the hour:
47 * * * * /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
#
# Run daily cron jobs at 4:40 every day:
40 4 * * * /usr/bin/run-parts /etc/cron.daily 1> /dev/null
#
# Run weekly cron jobs at 4:30 on the first day of the week:
30 4 * * 0 /usr/bin/run-parts /etc/cron.weekly 1> /dev/null
#
# Run monthly cron jobs at 4:20 on the first day of the month:
20 4 1 * * /usr/bin/run-parts /etc/cron.monthly 1> /dev/null
4

From /etc/anacrontab on my Ubuntu 9.10 system:

1       5       cron.daily       nice run-parts --report /etc/cron.daily
7       10      cron.weekly      nice run-parts --report /etc/cron.weekly
@monthly        15      cron.monthly nice run-parts --report /etc/cron.monthly
2

There is no such facility as far as Solaris is concerned. Just use regular crontab entries for daily tasks.

1

OpenSuse 42.x Update :

/etc/crontab shows a file /usr/lib/cron/run-crons that is supposed to run every 15 minutes.

/usr/lib/cron/run-crons in turn ( has may lines of code ) which is looking for a variable called DAILY_TIME in /etc/sysconfig/cron

The file shows;

# At which time cron.daily should start. Default is 15 minutes after booting
# the system. Example setting would be "14:00".
# Due to the fact that cron script runs only every 15 minutes,
# it will only run on xx:00, xx:15, xx:30, xx:45, not at the accurate time
# you set.

DAILY_TIME=""

Set it to the time you need and restart cron via;

systemctl restart cron.service

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .