![](/img/trans.png)
[英]Executing commands remotely on few servers and running elapsed timer while running
[英]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.