用sudo运行命令给出不同的结果

我通过ssh在debian squeeze服务器上与root连接。 如果我执行命令:

/usr/lib/nagios/plugins/check_procs -w 1:1 -c 1:1 -a '/usr/local/freeswitch/bin/freeswitch' 

我得到的结果是:

 PROCS OK: 1 process with args '/usr/local/freeswitch/bin/freeswitch' 

如果我执行:

 sudo /usr/lib/nagios/plugins/check_procs -w 1:1 -c 1:1 -a '/usr/local/freeswitch/bin/freeswitch' 

我得到:

 PROCS CRITICAL: 2 processes with args '/usr/local/freeswitch/bin/freeswitch' 

在这里我的/ etc / sudoers:

 Defaults env_reset root ALL=(ALL) ALL nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/ 

然而,sudo也以root身份执行命令,我得到另一个结果。 怎么可能? 在其他机器与debian lenny我没有问题,两个命令给出了相同的结果。

我想你所看到的是由check_procs使用的底层“ps”命令返回的命令行数量的结果。

在sudo blah … blah的情况下,可能是整个命令sudo blah …. blah被显示为一个进程以及简单的只有blah的进程。

这就是为什么当你pipe道命令如grep时,通常必须包含一个命令来摆脱grep命令本身。

例如:

  ps -aef | grep -v grep | grep xinetd