Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to send a SIGTERM (or other) signal to a process inside ssh, for example:

ssh hostname 'sleep 10; echo done'

What can I do to interrupt the sleep command? If I press ctrl-c, the ssh command gets interrupted.

share|improve this question
    
Are you looking for something as described in the following question? How to inject commands at the start of an interactive SSH session? Unfortunately the only answer is not probably suitable for you. –  pabouk Feb 13 at 19:02
add comment

3 Answers 3

It is possible to propagate ctrl+c through to the remote process by implementing an "EOF to SIGHUP" converter via a named pipe on the remote host (see: ssh command unexpectedly continues on other system after ssh terminates).

ssh localhost '
TUBE=/tmp/myfifo.fifo
rm -f "$TUBE"
mkfifo "$TUBE"
<"$TUBE" sleep 100 &  appPID=$!
dd of="$TUBE" bs=1 2>/dev/null
kill $appPID
#kill -TERM -- -$$  # kill entire process group
rm -f "$TUBE"
'
share|improve this answer
add comment

If you knew the pid of the remote process then you could do: ssh hostname 'kill -TERM $pid'

share|improve this answer
    
Pity, I hope this is not the only solution :) Thanks for your answer! –  jabalsad Jan 25 '12 at 11:38
add comment

-t might do what you want (see http://superuser.com/a/20708/36198). Unfortunately, if you want to read stdin as well, you'll need to do that in two steps, only having Ctrl+C for the second, e.g.

tmp=$(bzcat foo.bz2 | ssh $user@$host '
    t=$(mktemp -t foo.XXXXXXXXXXX);
    cat >"$t";
    echo "$t";
')
ssh -t $user@$host "./cmd \"$tmp\""
ssh $user@$host "rm -f \"$tmp\""    
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.