Reputation: 5739
I've built a Fabric fabfile with a simple task to give me a remote interactive shell:
def shell():
open_shell()
I do this instead of a raw ssh to save typing: the fabfile already has key paths, host name, etc for each remote config.
Invoking
fab shell
works, but if I ever hit CTRL+C in the shell, it kills the whole connection.
Is it possible to make CTRL+C go to the remote interactive shell instead?
Upvotes: 4
Views: 1811
Reputation: 159
The only one of the ssh libraries I've seen for python that uses the signal passing mechanism described by the ssh rfc is the one from chilkatsoft. From RFC 4254:
6.9. Signals
A signal can be delivered to the remote process/service using the
following message. Some systems may not implement signals, in which
case they SHOULD ignore this message.
byte SSH_MSG_CHANNEL_REQUEST
uint32 recipient channel
string "signal"
boolean FALSE
string signal name (without the "SIG" prefix)
'signal name' values will be encoded as discussed in the passage
describing SSH_MSG_CHANNEL_REQUEST messages using "exit-signal" in
this section.
You could modify fabric to use that instead of the 'ssh' library, and then add a signal handler to fabric to catch the SIGINT and call SendReqSignal() to send it along to the remote process.
or you could probably just wrap fabric with stty invocations to change the INTR character to something else, and then change it back afterwards.
#!/bin/sh
stty intr ^U
<whatever to invoke fabric>
stty intr ^C
Upvotes: 2