cron.daily jobs not running

I created 3 daily cron jobs to run.

Below are the three that are placed in etc/cron.daily

rkhunter.sh

#!/bin/sh
(
rkhunter --versioncheck
rkhunter --update
rkhunter --cronjob --report-warnings-only
) | mail -s 'rkhunter Daily Run (my server)' [email protected]

chkrootkit.sh

#!/bin/bash
chkrootkit | mail -s "chkrootkit Daily Run (my server)" [email protected]

logwatch.sh

#!/bin/sh
(
logwatch
) | mail -s 'logwatch Daily Log (my server)' [email protected]

I replaced [email protected] ofcourse with my email.

If I run this cronjob manually it works fine ./nameoffile.sh

But it doesn't run daily, what can be the cause or how can I check into this?


Solution 1:

According to this response, the problem lies with the .sh extension. Remove that (so for example rename your file from rkhunter.sh to rkhunter.

To confirm run the following command run-parts --test /etc/cron.daily

If your script (rkhunter) is included in the results, all is good. For more information on the run-parts command, read the man pages on it man run-parts

Solution 2:

In my system it was because anacron wasn't installed.

grep run-parts /etc/crontab

17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

So either install anacron or remove the test -x /usr/sbin/anacron

Solution 3:

I think files with extensions are ignored.

run:

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

If you don't see your scripts listed, remove the .sh extensions and try again.