If you are reading this you probably know what /etc/cron.hourly/ , /etc/cron.daily/ and so on does. What you might not know is that on CentOS, RHEL, Fedora you can name a script living in these directories whatever. You can name them my_script.sh or your_script.pl and cron will run them.
Let’s test this, first on a CentOS server (it is the same behavior on Fedora and RHEL).
stan@centos1 ~ % ls -l /etc/cron.daily
total 8
-rwxr-xr-x. 1 root root 189 Jan 4 2018 logrotate
-rwxr-xr-x 1 root root 189 May 16 16:55 logrotate.sh
stan@centos1 ~ % sudo run-parts --test /etc/cron.daily
/etc/cron.daily/logrotate
/etc/cron.daily/logrotate.sh
As you can see we have two files under /etc/cron.daily/, and run-parts recognized both as cron jobs and it’s ready to execute them when time comes.
What about Debian and Ubuntu?
pan@debian2 ~ % ls -l /etc/cron.daily
total 28
-rwxr-xr-x 1 root root 1478 Dec 7 12:31 apt-compat
-rwxr-xr-x 1 root root 355 Dec 29 2017 bsdmainutils
-rwxr-xr-x 1 root root 1187 Apr 19 2019 dpkg
-rwxr-xr-x 1 root root 377 Aug 29 2018 logrotate
-rwxr-xr-x 1 root root 1123 Feb 10 2019 man-db
-rwxr-xr-x 1 root root 249 Sep 27 2017 passwd
-rwxr-xr-x 1 root root 249 May 16 18:55 passwd.sh
pan@debian2 ~ % sudo run-parts --test /etc/cron.daily
/etc/cron.daily/apt-compat
/etc/cron.daily/bsdmainutils
/etc/cron.daily/dpkg
/etc/cron.daily/logrotate
/etc/cron.daily/man-db
/etc/cron.daily/passwd
Wait, what?! That’s correct, we have seven scripts but run-parts only recognized six. This is going to be the same on Ubuntu. It is a known bug since 2006 (bug 38022) which has been fixed and unfixed since then. More details can be found in the official Ubuntu documentation.
Now that you know this, be careful how you name your /etc/cron.* files 🙂