简体   繁体   English

远程运行命令会返回意外的输出

[英]Running commands remotely returns unexpected output

I want to kill a process remotely and I use ssh -i command like this: 我想远程杀死一个进程,并且使用ssh -i命令,如下所示:

ssh -i $app_rsa_file_path $app_server_user@$app_server_ip "ps aux | grep java | grep billing | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1"

if I run command directly on the server, it works fine; 如果我直接在服务器上运行命令,它将正常工作; but in remote version it seems that awk has no effect and the command passes the whole output of ps aux | grep java | grep billing 但是在远程版本中, awk似乎没有任何作用,该命令将传递ps aux | grep java | grep billing的整个输出。 ps aux | grep java | grep billing ps aux | grep java | grep billing to kill and I get this: ps aux | grep java | grep billing kill ,我得到这个:

kill: invalid option -- 'D'

Usage:
 kill [options] <pid> [...]

Options:
 <pid> [...]            send signal to every <pid> listed
 -<signal>, -s, --signal <signal>
                        specify the <signal> to be sent
 -l, --list=[<signal>]  list all signal names, or convert one to a name
 -L, --table            list all signal names in a nice table

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see kill(1).

Any idea about the reason? 知道原因吗?

您使用双引号“,因此您需要转义$特殊字符:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM