I want to be able to send signals (SIGINT is the most important) through ssh.
This command:
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?
Edit:
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"
Edit2:
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.
ssh
must be more complicated than what you show as examples, because you can get the behavior you want with a simple rearrangement:sleep 1000 && ssh server "echo f" > foo
(It has to be&&
, not;
, so that killingsleep
prevents thessh
command from running.) If I'm right, please make your examples more representative of your actual usage, so a better answer can be given. – Warren Young Jun 04 '12 at 21:31echo $SHELL | grep -E "/(t)?csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID
;' zcat\ $PARALLEL_SEQ\ log.gz\ |\ bzip2 – Ole Tange Jun 04 '12 at 23:30scp
it to the remote, and execute it in place? Killing the client sidessh
will stop the server-side script from producing output then, wouldn't it? – Warren Young Jun 05 '12 at 00:35