I want to be able to send signals (SIGINT is the most important) through ssh.
ssh server "sleep 1000;echo f" > foo
will start sleep on server and after 1000 seconds it will put 'f\n' in the file foo on my local machine. If I press CTRL-C (i.e. send SIGINT to ssh) it will kill ssh, but it will not kill sleep on the remote server. I want it to kill sleep on the remote server.
So I tried:
ssh server -t "sleep 1000;echo f" > foo
But if stdin is not a terminal I get this error:
Pseudo-terminal will not be allocated because stdin is not a terminal.
and then SIGINT is still not forwarded.
So I tried:
ssh server -t -t "sleep 1000;echo f" > output
But then the output in foo is not 'f\n' but instead 'f\r\n' which is disastrous in my situation (as my output is binary data).
In the above I use "sleep 1000;echo f", but in reality that is supplied by the user, thus it can contain anything. However, if we can make it work for "sleep 1000;echo f" we can most likely make it work for all realistic situations.
I really do not care about getting a pseudo-terminal at the other end, but I have been unable to find any other way of getting ssh to forward my SIGINT.
Is there another way?
The user could give commands that read binary data from stdin, such as:
seq 1000 | gzip | ssh server "zcat|bzip2; sleep 1000" | bzcat > foo
The user could give commands that are cpu intensive, such as:
ssh server "timeout 1000 burnP6"
The version that seems to work for me is:
your_preprocessing | uuencode a | ssh -tt -oLogLevel=quiet server "stty isig -echoctl -echo ; uudecode -o - | your_command | uuencode a" | uudecode -o - | your_postprocessing
Thanks to digital_infinity for pointing me in the right direction.