I created a shell script to be run daily, and as such I placed it into /etc/cron.daily, made it executable and even restarted cron daemon, but it was still not working. After investigating cron manual, the reason was simply because the name of the script contained a dot in it! (it ended with .sh)!!!
To make sure your script gets executed, do the following:
- move your script into /etc/cron.daily|weekly|monthly folder
- make your script executable (chmod a+x /etc/cron.xxx/<my_script_name>)
- rename your script so that its name contains only lower|upper case letters, digits, underscore and hyphens (=> NO DOT => no .sh or .xxx extension)
- ensure your script will be called by running: run-parts –test /etc/cron.xxx/
(it outputs the name of all script that will be called, without actually calling them => make sure the name of your script is displayed)
That’s it!
If you want to immediately run your script the way cron does, run “run-parts –verbose /etc/cron.xxx”
sources
- man cron
7 Comments: Trackback URL | Comments RSS
February 28th, 2011 at 7:15 am
Very helpful.
April 9th, 2011 at 1:45 am
Stupid underscores messing me up!
The run-parts flags -test and -verbose need to be –test and –verbose (at least they do on my machine).
April 9th, 2011 at 1:47 am
^^^ WordPress is replacing double hypens with single hypens
July 6th, 2011 at 1:03 pm
Great tip! Now my cron works as expected.
January 12th, 2012 at 12:46 am
Very useful and very clear! Thank you.
(“man cron” tells it, but it is not so clear in stating that any extension MUST be avoided).
There are pages and pages on the web full of “tips” that don’t state this simple and MANDATORY issue (at least for me).
November 22nd, 2012 at 11:49 am
Thanks, I have to say I’m disappointed in that behavior from cron.daily (run-parts whatever).
Very far from following the least surprise rule at the very least.
My conclusion: all cron.x are unreliable and should be avoided like the plague.
crontab, on the other hand, works.
November 28th, 2012 at 3:53 pm
The misteries of linux…how could .sh extension influence execution of a script…that’s crazy!