Why your cron.daily script is not running

Updated , First Published by Pete Freitag

Over the years when setting up linux servers I have run into many different reasons that prevent cron.daily or cron.hourly scripts from executing. Today however, I ran into a whole new reason that I had never encountered before.

I ran into this problem on a Ubuntu Linux server. I placed a script in /etc/cron.daily/my_script.sh but it was not running each day.

I checked all the usual suspects, the reasons I was aware of that cause a cron script to be ignored:

But my problem was not any of the above. I found that you can execute the run-parts command in a test mode to see which scripts it would call in a directory. You can run it like this (it will not execute any of the scripts, it just outputs which ones it would execute):

run-parts --test /etc/cron.daily

My script was not listed in the output!

Well, that was comforting at least, but why my script omitted from the cron.daily scripts to execute? It turns out you cannot have a file extension on the script, so by renaming the script from my_script.sh to my_script it works!

To be a little bit more precise, the issue is that you can't have a . (dot) in the file name of your cron.daily or cron.weekly or cron.hourly scripts. This issue appears to be specific to certain linux distributions. It occurs on Ubuntu and Debian, but the same script may work fine on RedHat Linux servers.

Comments

Javier Lobo

Thanks! In my case, there was two of them not set as executable (chmod +x scriptfile).

ikomrad

Your post saved my life! or at least my backups. I was setting up backups on a new systems, and decided to copy an existing system. I noticed its backups were dated that same as when I set them up. The run-parts and extension tips did the trick. One thing., my scheduled backup command starts with '$(which duplicity)' Is there a way that I can verify it will work when cron runs it?

Anders Markendahl

This was ... exactly what I needed, the issue being file extension. Thank you

Tristan

Thanks for sharing this. I never would have guessed that a file extension would prevent a daily cron script from running!

Ivan V.

Thank you for sharing. I've got a lot of experience work with RH/CentOS, and only have a couple of servers with Debian. Little differences like this one can drive you nuts (sames script on the other servers works fine with the extension).

Winston

It's not the extension per se; it's the ".". But I'd never have guessed either.

Ali Kalamchi

Many thanks for this post. It really kept me confused why my script runs correctly manually but it won't run automatically with the other cron.daily scripts. The post is spot on !