Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a script in cron.daily that runs at a certain time every morning. I need to change the time that it is run.

How do I change the time cron.daily runs the scripts?

share|improve this question

migrated from stackoverflow.com Sep 22 '12 at 21:46

This question came from our site for professional and enthusiast programmers.

add comment

4 Answers

On Red Hat-style systems, this is controlled in /etc/crontab.

By default, cron.daily scripts are run at 4:02. Editing this file will modify that time.

# run-parts
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

On Debian/Ubuntu systems, this is controlled in /etc/crontab as well.

For example; a default Ubuntu 12.04 installation:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

And in either case, you may find more details about what syntax to use here: http://linux.die.net/man/5/crontab or by running man 5 crontab on almost any Linux system.

share|improve this answer
add comment

On openSUSE, the crontab looks like:

SHELL=/bin/sh
PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin
MAILTO=root
#
# check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly
#
-*/15 * * * *   root  test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1

The run-crons command verifies the timestamps of the files in /var/spool/cron/lastrun among other things. When the time since the last execution expired, it will run the cron file again.

The time can be influented by touching the file. For example, to set it to 2012-11-17 03:15:

touch -t 201211140315 /var/spool/cron/lastrun/cron.daily
share|improve this answer
add comment

If the line wasn't there, this will not solve anything.

Try finding where cron.daily is mentioned, with

grep -R cron.daily /etc

Then take it from there.

share|improve this answer
    
You have to be very carefully if you use these command. For example for my RedHat it returns /etc/crontab and /etc/anacrontab files. And if you remove lines with cron.daily entry you just simply turn off execution of all scripts which should be run daily (for me it is logrotate, tmpwatch, cups and so on). –  Lukasz Stelmach Aug 6 '10 at 9:28
2  
I didn't suggest to remove the line, the question was where to modify the cron.daily time. This is how you locate it (so this was more a "help them help themselves" kind of answer) –  mvds Aug 6 '10 at 9:34
add comment

You want to do two things:

  1. Remove the script from cron.daily and put in somewhere else.
  2. Add an entry to your crontab to run the specified script at the specified time:

00 10 * * * /path/to/script

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.