蓝鲸:主机频繁提示“You have new mail in /var/spool/mail/root” 定位解决


前些天安装蓝鲸的测试环境频繁出现You have new mail in /var/spool/mail/root,查看发现是/usr/local/gse/agent/bin/gsectl: line 19: ip: command not found,查了下报错频率基本上是每分钟报错一次。

[root@rbtnode1 install]# 
You have new mail in /var/spool/mail/root
[root@rbtnode1 install]# 
[root@rbtnode1 install]# tail -20f /var/spool/mail/root
        id D85A730F67A5; Sun,  8 Mar 2020 16:51:02 +0800 (CST)
From: "(Cron Daemon)" 
To: root@rbtnode1.localdomain
Subject: Cron  /usr/local/gse/agent/bin/gsectl watch
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
Message-Id: <20200308085102.D85A730F67A5@rbtnode1.localdomain>
Date: Sun,  8 Mar 2020 16:51:01 +0800 (CST)

/usr/local/gse/agent/bin/gsectl: line 19: ip: command not found

^C

看下目前为止的报错次数:

[root@rbtnode1 install]# grep "line 19: ip: command not found" /var/spool/mail/root |wc -l
15748
[root@rbtnode1 install]# 
You have new mail in /var/spool/mail/root
[root@rbtnode1 install]# grep "line 19: ip: command not found" /var/spool/mail/root |wc -l
15750

查看/usr/local/gse/agent/bin/gsectl文件,vi定位到19行:

     17 get_lan_ip  () {
     18    #
     19    ip addr | \
     20        awk -F'[ /]+' '/inet/{
     21                split($3, N, ".")
     22                if ($3 ~ /^192.168/) {
     23                    print $3
     24                }
     25                if (($3 ~ /^172/) && (N[2] >= 16)) {
     26                    print $3
     27                }
     28                if ($3 ~ /^10\./) {
     29                    print $3
     30                }
     31           }'
     32     return $?
     33 }
     34 export LAN_IP=$(get_lan_ip | head -1)

使用which ip 查看系统ip命令的路径:

[root@rbtnode1 install]# which ip
/usr/sbin/ip

尝试修改第19行,ip命令的调用改为绝对路径:/usr/sbin/ip

     19    /usr/sbin/ip addr | \

再次查看报错次数和最近的报错时间:

[root@rbtnode1 install]# grep "line 19: ip: command not found" /var/spool/mail/root |wc -l
15755

[root@rbtnode1 install]# tail -20f /var/spool/mail/root
        id 9647530F67A5; Sun,  8 Mar 2020 16:58:03 +0800 (CST)
From: "(Cron Daemon)" 
To: root@rbtnode1.localdomain
Subject: Cron  /usr/local/gse/agent/bin/gsectl watch
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
Message-Id: <20200308085803.9647530F67A5@rbtnode1.localdomain>
Date: Sun,  8 Mar 2020 16:58:02 +0800 (CST)

/usr/local/gse/agent/bin/gsectl: line 19: ip: command not found

后续观察没再发现这个报错计数增长,也没有16:58:03之后的报错信息,说明改动有效。