pathikrit pathikrit - 1 year ago 156
Bash Question

Why does pkill kill my SSH session?

I want to do something like this:

ssh bob@mycomputer "pkill -f $program; echo 'Done!'";

But, it seems like
is killing my ssh (I never see
). If I replace
with something else (say
), it works as expected.

Answer Source

Well seems really a good case here. The -f flag uses the full path of terminal and if its unable to get the process then it kills all the processes it could like pkill -f / which includes ssh. Refer here.

If you try pkill without -f then it works. You can also check ssh verbose (ssh -v) to see what is happening in the background.

Hope it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download