0

I put a rkhunter script in daily.cron on Apache Centos 7.

When I manually run the script, it works fine. but leaving it in daily.cron it fails to run.

I get this email every day instead.

/etc/cron.daily/rkhunter:

/etc/cron.daily/rkhunter: line 3: rkhunter: command not found

if you look in cron.daily you see a rkhunter script. inside that script this is the contents.

#!/bin/sh

OUTPUT=`rkhunter --update --cronjob --report-warnings-only --nocolors --skip-keypress`

if [ "$OUTPUT" != "" ]
 then
echo $OUTPUT | mail -s "[rkhunter] Warnings found for $(hostname)" email@example.com
fi

if i manually run

sh rkhunter 

from that directory it works. I tried to have a file extension on it rkhunter.sh but it was the same result so with or without the .sh extension i am not sure it makes a difference.

How can I get this script to run daily and not fail with command not found.

Zuriel
  • 101
  • 2
  • Is your script calling itself in its own script? Is it script inception (inscription o_O)? This line: `OUTPUT=\`rkhunter --update --cronjob --report-warnings-only --nocolors --skip-keypress\`` calls program "rkhunter" that is not found. Try changing it to absolute path. – yahol Mar 13 '18 at 13:16
  • **cron runs your command in a restricted environment.** ... Of particular note is the PATH is restricted to `/bin:/usr/bin`. The vast majority of *"my cron script doesn't work"* problems are caused by this restrictive path. If your command is in a different location you can solve this in a couple of ways: ... *provide the full path to `/path/to/rkhunter`* – HBruijn Mar 13 '18 at 13:34
  • full path worked @HBruijn – Zuriel Mar 13 '18 at 14:13

1 Answers1

0

Edit your crontab entry like so, as user that's supposed to run script:

# crontab -e

Add this line:

@daily /path/to/script.sh

Write and quit (press :wq:

:wq

Remove script from /etc/cron.daily/rkhunter.

yahol
  • 81
  • 1
  • 6