10

I want ssh to forward the SIGTERM signal to the remote command.

ssh root@localhost /root/print-signal.py

Get PID of ssh:

ps aux| grep print-signal

Kill the matching ssh process:

kill pid-of-ssh

Unfortunately only the ssh process itself gets the signal, not the remote command (print-signal.py). The remote command does not terminate :-(

How can I make ssh "forward" the SIGTERM signal to the remote command?

guettli
  • 25,042
  • 81
  • 346
  • 663
  • The print-signal.py script is from this answer: https://stackoverflow.com/a/5669030/633961 – guettli Jan 22 '18 at 09:11
  • 1
    https://stackoverflow.com/a/47581495/13317 – Kenster Jan 22 '18 at 14:38
  • Since there seems to be no answer, I created a new question: How to work around this? https://stackoverflow.com/questions/48419781/work-around-ssh-does-not-forward-signal – guettli Jan 24 '18 at 10:17
  • Does this help? https://unix.stackexchange.com/questions/103699/kill-process-spawned-by-ssh-when-ssh-dies – Tarun Lalwani Jan 24 '18 at 10:34
  • Maybe you should try to catch the signal Inside your Python script, I guess the signal is not transmitted since the script is not stopped but I can give us a hint of what's going on – Jaay Jan 31 '18 at 08:31

2 Answers2

1

I think you can do the following :

ssh root@localhost /root/print-signal.py

**Get PID of python file running **

ps aux| grep print-signal

Kill the matching ssh process:

ssh root@localhost "kill <pid>"

Here you are sending command to remote host .

Hope this solves your problem .

Sahil Aggarwal
  • 1,311
  • 1
  • 12
  • 29
0

Send via SSH this (tested on sleep process):

$(proc=$(pidof sleep) && kill $proc)