繁体   English   中英

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

[英]Running commands remotely returns unexpected output

我想远程杀死一个进程,并且使用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"

如果我直接在服务器上运行命令,它将正常工作; 但是在远程版本中, awk似乎没有任何作用,该命令将传递ps aux | grep java | grep billing的整个输出。 ps aux | grep java | grep billing 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).

知道原因吗?

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

暂无
暂无

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

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