Saturday, May 4, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 65351  / 1 Year ago, fri, january 6, 2023, 7:49:36

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?


More From » command-line

 Answers
2

There are two possible suspects that usually cause cron jobs not being able to run.



The first is permissions problems, that is a user can run the script/command but the cron daemon cannot because the job is in the wrong user's cron jobs. For example the user creates a script or runs a command with elevated privileges i.e using sudo, then adds the tested script/command to his list of cron jobs (crontab). The result is that the user's cron job will not be able to run since it needs elevated privileges.




  • To put a cron job in current user's crontab type crontab -e

  • To put a cron job in root's crontab type sudo crontab -e



The second reason is the paths, in order to be sure that the script will execute, the user must add the full path to the script to be executed in crontab. Another solution would be to expand the root users PATH variable by putting the following line at the top of their crontab file:



PATH=/usr/sbin:/usr/bin:/sbin:/bin


as the community wiki mentions.



You may want to read the community wiki about cron as it provides further details about the above.


[#29783] Saturday, January 7, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tinchir

Total Points: 300
Total Questions: 116
Total Answers: 119

Location: American Samoa
Member since Sun, Jan 17, 2021
3 Years ago
tinchir questions
Tue, Sep 14, 21, 23:11, 3 Years ago
Mon, Dec 19, 22, 13:00, 1 Year ago
Sat, Feb 5, 22, 11:36, 2 Years ago
Mon, Aug 8, 22, 02:16, 2 Years ago
;