Reputation: 44395
I have a gentoo Linux system and a strange behavior of crontab. As root
user, and as I understand the documentation, the command
crontab -l
lists all crontab jobs defined for the current user, root
(There are no cronjobs defined for any other used). All listed cronjobs are also defined in the file /etc/cronjob
.
However, there are two more crontab
files located in /etc/cron.d
, which define a cronjob each:
/etc/cron.d/testcron1
/etc/cron.d/testcron2
Although not listed with crontab -l
, the cronjob defined in the file /etc/cron.d/testcron1
is executed. The other cronjob defined in the file /etc/cron.d/testcron2
is NOT executed.
This all does not make sense, so I have two questions:
crontab -l
list not all cronjobs?/etc/cron.d
be registered somewhere, or is a restart of a daemon/service required? Why is the one started, and not the other one (the executable works fine, though). Upvotes: 0
Views: 684
Reputation: 3804
The command crontab is used to maintain/manage crontab files for individual users. These files are usually located in /var/spool/cron/crontabs
.
If crontab -l
dose not show any cron jobs then this user currently has no individual cron jobs. This dose not mean that there are no cron jobs in /etc/cron* taht will run with the privileges of this user. crontab
will not operate on the files in /etc/cron*. It is a tool for only managing individual (per user) cron jobs held in /var/spool/cron/crontabs
.
Now lets see how the different cron jobs get executed. Form the manpage of the cron daemon we can read:
cron searches its spool area (/var/spool/cron/crontabs) for crontab files (which are named after accounts in /etc/passwd); ...
cron also reads /etc/crontab, which is in a slightly different format (see crontab(5)).
as well as:
Additionally, in Debian, cron reads the files in the /etc/cron.d directory. cron treats the files in /etc/cron.d as in the same way as the /etc/crontab file...
(I think this applies to gentoo as well...)
About restarting we can read:
cron then wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute...
Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on the /etc/crontab file) has changed, and if it has, cron will then examine the modtime on all crontabs files and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified. Note that the crontab(1) command updates the modtime of the spool directory whenever it changes a crontab.
So the crontab
command is for user specific corn jobs while the files in /etc/cron*
are more for system cron jobs.
No manual triggering is needed to activate a new cron job.
Upvotes: 1