简体   繁体   English

带Fabric的远程交互式Shell被CTRL-C杀死

[英]Remote interactive shell with Fabric is killed by CTRL-C

I've built a Fabric fabfile with a simple task to give me a remote interactive shell: 我用一个简单的任务构建了一个fabric fabfile,为我提供了一个远程交互式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. 我这样做是为了代替原始ssh来保存输入内容:fabfile已经具有每个远程配置的键路径,主机名等。

Invoking 调用中

fab shell

works, but if I ever hit CTRL + C in the shell, it kills the whole connection. 可以,但是如果我在外壳中按CTRL + C ,它将终止整个连接。

Is it possible to make CTRL + C go to the remote interactive shell instead? 是否可以使CTRL + C转到远程交互式外壳?

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. 我见过的python唯一使用ssh rfc描述的信号传递机制的ssh库是chilkatsoft的库。 From RFC 4254: 从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. 您可以修改结构以使用该结构而不是'ssh'库,然后向该结构添加一个信号处理程序以捕获SIGINT并调用SendReqSignal()将其发送到远程进程。

or you could probably just wrap fabric with stty invocations to change the INTR character to something else, and then change it back afterwards. 或者您可能只是用stty调用包装结构,以将INTR字符更改为其他字符,然后再将其更改回。

#!/bin/sh
stty intr ^U
<whatever to invoke fabric>
stty intr ^C

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM