首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cron脚本找不到logwatch和chkrootkit

cron脚本找不到logwatch和chkrootkit
EN

Unix & Linux用户
提问于 2018-08-27 20:33:50
回答 1查看 301关注 0票数 2

我有一个问题,可能与PATH变量有关。

这是我收到的一封关于运行在cron中的脚本的错误邮件:

代码语言:javascript
复制
Cron Daemon 

    05:08 (15 hours ago)

    to root, bcc: me
    mail: Null message body; hope that's ok
    tar: Fjerner indledende '/' fra medlemsnavne
    mail: Null message body; hope that's ok
    /home/user/bin/checkSystem: linje 16: chkrootkit: command not found
    mail: Null message body; hope that's ok
    /home/user/bin/checkSystem: linje 21: logwatch: command not found
    /home/user/bin/checkSystem: linje 22: logwatch: command not found
    /home/uesr/bin/checkSystem: linje 23: logwatch: command not found
    mail: Null message body; hope that's ok
    mail: Null message body; hope that's ok
    mail: Null message body; hope that's ok

我只是将脚本的所有者从用户更改为root

代码语言:javascript
复制
$ls -sail /home/user/bin/checkSystem 
541784 4 -rwxr-x--- 1 root root 1235 aug 23 14:05 /home/user/bin/checkSystem

crontab -e

代码语言:javascript
复制
 1 # Edit this file to introduce tasks to be run by cron.
 2 #
 3 # Each task to run has to be defined through a single line
 4 # indicating with different fields when the task will be run
 5 # and what command to run for the task
 6 #
 7 # To define the time you can provide concrete values for
 8 # minute (m), hour (h), day of month (dom), month (mon),
 9 # and day of week (dow) or use '*' in these fields (for 'any').#
10 # Notice that tasks will be started based on the cron's system
11 # daemon's notion of time and timezones.
12 #
13 # Output of the crontab jobs (including errors) is sent through
14 # email to the user the crontab file belongs to (unless redirected).
15 #
16 # For example, you can run a backup of all your user accounts
17 # at 5 a.m every week with:
18 # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
19 #
20 # For more information see the manual pages of crontab(5) and cron(8)
21 #
22 # m h  dom mon dow   command
23 0 5 * * 1 /home/user/bin/checkSystem

下面是脚本:

代码语言:javascript
复制
#!/bin/bash
 2 date=`date +%d-%m-%y`
 3 mail="mail.org"
 4
 5 ## rkhunter
 6 #rkhunter --update
 7 rkhunter --checkall --cronjob --report-warnings-only > rkhunter-check-$date.log
 8 mail -A rkhunter-check-$date.log -s "rkhunter-check" $mail < /dev/null 2>&1
 9 rm rkhunter-check-$date.log
10 tar -cf rkhunter-log-$date.tar /var/log/rkhunter.log
11 gzip rkhunter-log-$date.tar
12 mail -A rkhunter-log-$date.tar.gz -s "rkhunter-log" $mail < /dev/null 2>&1
13 rm rkhunter-log*.tar.gz
14
15 ## chkrootkit
16 chkrootkit > chkrootkit-$date.log
17 mail -A chkrootkit-$date.log -s "chkrootkit" $mail < /dev/null 2>&1
18 rm chkrootkit-$date.log
19
20 ## logwatch
21 logwatch --output html --detail High --range All > logwatch-all-$date.html
22 logwatch --output html --detail High --range Today > logwatch-today-$date.html
23 logwatch --output html --detail High --range Yesterday > logwatch-yesterday-$date.html
24 mail -A logwatch-all-$date.html -s "logwatch all" $mail < /dev/null 2>&1
25 mail -A logwatch-today-$date.html -s "logwatch today" $mail < /dev/null 2>&1
26 mail -A logwatch-yesterday-$date.html -s "logwatch yesterday" $mail < /dev/null 2>&1
27 rm -f logwatch-*.html
28
29 ## testing command
30 #echo "Just testing my sendmail gmail relay" | mail -s "Sendmail gmail Relay" mail.org

怎么回事?

编辑:

代码语言:javascript
复制
(root@host)-(20:39:01)-(/home/user)
$which logwatch
/usr/sbin/logwatch
(root@host)-(20:39:06)-(/home/user)
$which chkrootkit
/usr/sbin/chkrootkit
(root@host)-(20:39:16)-(/home/user)
$which rkhunter
/usr/bin/rkhunter
(root@host)-(20:39:22)-(/home/user)
$
EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2018-08-27 20:56:21

当运行cron作业时,无法找到“logwatch”。由于安装了logwatch,这可能意味着它在路径中丢失了。您可以通过将'/usr/sbin‘添加到/etc/crontab文件中的路径来解决这个问题。

如果您没有编辑/etc/crontab的权限,则另一种解决方法是直接在脚本中使用可执行文件的完整路径。

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/465179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档