Skip to content
Advertisement

Why does this not kill remote process?

The follow command works in a local terminal:

ps aux | grep "script.py" | awk {'print $2'} | xargs kill -2

But this command doesn’t work remotely:

ssh -o ConnectTimeout=6 john@remote-pc ps aux | grep "script.py" | awk {'print $2'} | xargs kill -2

…even though script.py on remote belongs to john, the user we are ssh as. I can ping successfully and other commands are successful.

Advertisement

Answer

You need to escape the pipes to cause them to be passed to the ssh command rather than being executed by your local shell otherwise everything after ps aux is executed on your local machine.

ssh -o ConnectTimeout=6 john@remote-pc ps aux | grep "script.py" | awk {'print $2'} | xargs kill -2
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement