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):
#!/bin/bash
/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 ?
Best Answer
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 :run-parts
, i.e. [a-zA-Z0-9_-].So don't use extension like
.sh
.If not :
chmod +x /etc/cron.hourly/yourScript
#!/bin/bash
for example).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.service crond status
.If not :
service crond stop
thenservice crond start
/var/log/cron
contains the errorBAD 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)./etc/cron.d/0hourly
exists and contains the line01 * * * * root run-parts /etc/cron.hourly