I have a script in /etc/cron.hourly :

-rwxr-xr-x 1 root root 85 Dec  6 19:05 /etc/cron.hourly/nvidia_to_exclusive

containing (with an empty line at the end):


/usr/bin/nvidia-smi -c 1 > /home/user/nvidia-smi_set_exclusive.log

The script isn't executed by cron at all, even if using run-parts /etc/cron.hourly successfully execute it.

What could be missing ?

  • 2
    Does anything show in /var/log/cron? eg mine says Dec 11 16:01:01 mercury7 CROND[30644]: (root) CMD (run-parts /etc/cron.hourly) Dec 11 16:01:01 mercury7 run-parts(/etc/cron.hourly)[30644]: starting 0anacron Dec 11 16:01:01 mercury7 run-parts(/etc/cron.hourly)[30667]: finished 0anacron. Errors may show, here. Dec 11 '18 at 21:11
  • No, except when I manually call run-parts /etc/cron.hourly, then it say that it started/fnished Anacron0, then the same for my script. It's seems that run-parts /etc/cron.hourly isn't called.
    – Adrian B.
    Dec 11 '18 at 21:26
  • Is it set executable? :)
    – tink
    Dec 11 '18 at 21:36
  • 3
    What be the contents of /etc/crontab?
    – RudiC
    Dec 11 '18 at 21:51
  • @tink yes, I don't think run-parts would works without that (and confirmed by ls anyway) :).
    – Adrian B.
    Dec 11 '18 at 22:21

The problem was that the cron service was inactive.

While I'm here, I'll summarize all the steps I've found to make a script in /etc/cron.hourly/ work :

  • Check that the name of your script is only using valid characters for run-parts, i.e. [a-zA-Z0-9_-].
    So don't use extension like .sh.
  • Check that your script is executable.
    If not : chmod +x /etc/cron.hourly/yourScript
  • Check that your script contains the shebang at the top (#!/bin/bash for example).
  • Check that your script runs with run-parts :
    run-parts --test /etc/cron.hourly → your script should be printed.
    run-parts /etc/cron.hourly→ your script should be executed.
    You can check at the end of /var/log/cron if your script successfully finished.
  • Check that cron is running with service crond status.
    If not : service crond stop then service crond start
  • Check if your /var/log/cron contains the error BAD FILE MODE (/etc/cron.d/0hourly).
    If it's the case, you probably need to execute chmod 0644 /etc/cron.d/0hourly (cron does not like this file to be executable).
  • Check - at least by default on CentOS 7 - that /etc/cron.d/0hourly exists and contains the line
    01 * * * * root run-parts /etc/cron.hourly
  • 1
    Excellent self-answer, glad you got it working. You should accept your answer as well, just to close the cycle
    – ivanivan
    Dec 12 '18 at 0:29
  • Thanks for sharing! Helped a lot! Aug 9 '21 at 13:24
  • Oh boy, thank you! We had the .sh extension in one of our scripts and nobody noticed for TWO YEARS that this script did actually never run...
    – Daywalker
    Aug 20 '21 at 6:40

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.