Does RHEL/CentOS execute all cronjob files under /etc/cron.d/*, or just some of them?

This is a Red Hat Enterprise Linux 5 system (RHEL). We manage this system using CFengine.

We have several cronjobs which are running twice as often as usual. I checked the cronjobs under /etc/cron.d/ and this directory contains the actual script called host-backup, and also contains a cfengine backup file called host-backup.cfsaved, as so:

/etc/cron.d/host-backup
/etc/cron.d/host-backup.cfsaved

Does this operating system execute all files at /etc/cron.d/*, or does it only execute files which match a certain pattern. Can I configure this, and where is this defined?

I cannot find this answer in the RHEL or CentOS documentation.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

(If you’re paying for Red Hat support, you should ask them this kind of questions. This is exactly what you’re paying for!)

From the RHEL5 crontab(5) man page:

If it exists, the /etc/cron.d/ directory is parsed like the cron spool directory, except that the files in it are not user-specific and are therefore read with /etc/crontab syntax (the user is specified explicitly in the 6th column).

(Is there a simpler way of reading RHEL man pages without having access to it? At least this way I could see that this paragraph is part of the Red Hat patch, so it’s not a standard Vixie Cron 4.1 feature.)

Looking at the source, I see that the following files are skipped: .*, #*, *~. *.rpmnew, *.rpmorig, *.rpmsave. So yes, your *.cfsaved files are read in addition to the originals.

Method 2

I think the reason you’ve had difficulty tracking down the answer is that it’s not a Red Hat-specific question. The problem you’re seeing is part of the standard functionality of cron – each file in the directory you identify is automatically treated as a separate job.

So, the short answer to your question is “yes, all files are executed”. This is not something I think that can be configured.

Method 3

Here is the answer from RedHat support:

Please be informed that all files under cron.d directory are examined and executed, it’s basically an extension of /etc/crontab file (ie; same effect if you add the entries to /etc/crontab file)

So, to answer my question “Does this operating system execute all files at /etc/cron.d/*, or does it only execute files which match a certain pattern. Can I configure this, and where is this defined?”

All files under /etc/cron.d/* are executed (Although it seems that certain file extensions such as .rpmsave, *~, etc are ignored, according to documentation in the source files). It is not possible to configure this via a configuration file. Configuring this is probably possible if the source is recompiled. This behavior is mentioned in the documentation contained with the source, but doesn’t appear in any manual or man page that I can find.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments