使用ssh执行远程命令xargs kill -9无法使用
今天在写脚本的时候遇到一个问题,需求是通过本机远程连接到其他服务器,杀掉之前提起的nmon进程,然后再返回本机
于是命令如下(以本机localhost为例):
ssh localhost "ps -ef | grep "nmon" | grep -v grep | awk -F ' ' '{print $2}'|tail -1| xargs kill -9;exit"
(ssh已经做了无密码登录,提起nmon进程的脚本没问题,问题只出现在kill进程)
执行以上命令后,这时问题出现了
返回信息:
[root@svt112 nmon]# ssh localhost "ps -ef | grep "nmon" | grep -v grep | awk -F ' ' '{print $2}'|tail -1| xargs kill -9;exit"
Usage:
kill [options] <pid|name> [...]
Options:
-a, --all do not restrict the name-to-pid conversion to processes
with the same uid as the present process
-s, --signal <sig> send specified signal
-q, --queue <sig> use sigqueue(2) rather than kill(2)
-p, --pid print pids without signaling them
-l, --list [=<signal>] list signal names, or convert one to a name
-L, --table list signal names and numbers
-h, --help display this help and exit
-V, --version output version information and exit
For more details see kill(1).
单独执行 ps -ef | grep "nmon" | grep -v grep | awk -F ' ' '{print $2}'|tail -1| xargs kill -9 是没有问题的,但是不知道为什么加上ssh去执行就失败了