简体   繁体   中英

Running commands remotely returns unexpected output

I want to kill a process remotely and I use ssh -i command like this:

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 ps aux | grep java | grep billing ps aux | grep java | grep billing to kill and I get this:

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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