0

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 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?

Zeinab Abbasimazar
  • 9,835
  • 23
  • 82
  • 131

1 Answers1

1

you use double-quotes " so you need to escape the $ special character:

maskacovnik
  • 3,080
  • 5
  • 20
  • 26
Lee HoYo
  • 1,217
  • 9
  • 9