242

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.

freiheit
  • 14,334
  • 1
  • 46
  • 69
warren
  • 17,829
  • 23
  • 82
  • 134
  • 2
    On [NetBSD](http://netbsd.org), the times for the daily,weekly, monthly cronjobs are set in root's crontab. – hd1 Nov 17 '14 at 01: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](https://access.redhat.com/support/policy/updates/errata#Life_Cycle_Dates)" (similar to [end of life](https://en.wikipedia.org/wiki/End-of-life_(product))). – Trevor Boyd Smith Jan 01 '18 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: https://access.redhat.com/articles/3078#RHEL6 – warren Jan 04 '18 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.) – Trevor Boyd Smith Jan 04 '18 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 04 '18 at 18:13

10 Answers10

186

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

Richard Holloway
  • 7,256
  • 2
  • 24
  • 30
  • 2
    Is there any reason behind this? I can only assume it'd be the quietest time on the server. – The Pixel Developer May 13 '10 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 – Narendra Jaggi Jan 02 '16 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. – Jordan Reiter Jan 21 '16 at 15:57
  • 5
    This is no longer valid answer for CentOS 6 or higher, scroll down for more. – lzap Oct 24 '16 at 07:53
  • 1
    cant find it in /etc/crontab on CO 7 – snh_nl Sep 01 '20 at 15:40
90

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

leonbloy
  • 2,028
  • 17
  • 23
  • 9
    This is the case with `CentOS 6`. Thanks. – mbrownnyc Jul 22 '13 at 15:59
  • 4
    That means 5am every "1" days?. Sorry, but this answers nothing. – elysch May 13 '16 at 16:50
  • 3
    @elysch Let me repeat the last line of my answer: See also "man anacrontab" – leonbloy May 13 '16 at 17:53
  • 3
    Good explanation of anacron [here](http://www.thegeekstuff.com/2011/05/anacron-examples/). 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 ). – storm_m2138 Jul 14 '16 at 17:40
  • 3
    @mbrownnyc and also CentOS-7 too – Trevor Boyd Smith Jan 01 '18 at 17:30
  • This is also the case on `CentOS 7`. Thank you. – SebMa Sep 06 '22 at 13:57
52

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

Spechal
  • 741
  • 6
  • 10
17

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).

darklion
  • 386
  • 2
  • 7
  • thx a lot! SuSE is rather opaque to me and I appreciate your answer. – dr0i Aug 02 '16 at 08: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 '20 at 08: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.

Sven
  • 97,248
  • 13
  • 177
  • 225
  • 3
    This is the right file for Ubuntu Lucid 10.04 LTS. My default setting is 6:25am for cron.daily. – geekQ Aug 08 '11 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 06 '15 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. – WinEunuuchs2Unix Mar 01 '17 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.

Daniel Santos
  • 77
  • 1
  • 1
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
paddy
  • 238
  • 2
  • 7
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
Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
2

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

jlliagre
  • 8,691
  • 16
  • 36
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
MarcoZen
  • 189
  • 1
  • 5