0

I have a shell script that I'm looking to run daily, (to update CentOS and send out a confirmation email via SSMTP). The script is working ok, and sits in /etc/cron.daily, the problem is that it's running hourly, not daily at the time I specified.

My /etc/crontab file looks like this:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
05 13   * * *   root run-parts /etc/cron.daily
05 13   * * 6   root run-parts /etc/cron.weekly

Now, after editing this file manually, I read that I should have instead used the 'crontab -e' command, which I did, and the output looks like this:

05 13   * * *   root run-parts /etc/cron.daily
05 13   * * 6   root run-parts /etc/cron.weekly

I also read that /etc/anacrontab has an effect on when jobs run, the output of this looks like 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

My intention was for the script to run at 13:05PM daily, however the script is actually running hourly at around 40 minutes past the hour, and I can't see anywhere in these 3 files where that's being triggered.

I happily schedule cron jobs with success in Ubuntu, but CentOS is proving to be a tad more complicated. Have I made a glaring mistake somewhere?

Any help greatly appreciated.

1
  • Finally got it working, cleared out the entries in crontab -e (no effect), commented out the cron.daily line in anacron and it finally started using the lines I'd put in /etc/crontab. May 12, 2016 at 8:55

1 Answer 1

0

After doing

crontab -e

add something as simple as:

@daily sh /path/to/myscript

That should execute myscript every day.

If you want an specific hour of the day:

0 16 * * * sh /path/to/myscript

would execute the script every day at 16:00

More useful info

4
  • Thanks for the reply. In this example, where would I define the time @daily runs? May 11, 2016 at 11:50
  • I updated my answer :)
    – sysfiend
    May 11, 2016 at 11:52
  • Thanks, so my crontab -e already contains: 05 13 * * * root run-parts /etc/cron.daily I'll update it to read 05 13 * * * sh /etc/cron.daily/autoupdate May 11, 2016 at 12:07
  • I'm still getting the job running at random times: ltccentostest - autoupdate finished at Wed 11 May 15:46:03 BST 2016. Server will now reboot. May 11, 2016 at 14:53

You must log in to answer this question.

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