gpt4 book ai didi

python - 使用 Fabric 的远程交互 shell 被 CTRL-C 杀死

转载 作者:太空宇宙 更新时间:2023-11-03 11:34:09 24 4
gpt4 key购买 nike

我用一个简单的任务构建了一个 Fabric fabfile 来给我一个远程交互式 shell:

def shell():
open_shell()

我这样做而不是原始 ssh 以节省输入:fabfile 已经有每个远程配置的关键路径、主机名等。

调用

fab shell

有效,但是如果我在 shell 中点击 CTRL+C,它会终止整个连接。

是否可以让 CTRL+C 转到远程交互式 shell?

最佳答案

我见过的唯一一个使用 ssh rfc 描述的信号传递机制的 python ssh 库是来自 chilkatsoft 的库。来自 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.

您可以修改 fabric 以使用它而不是“ssh”库,然后向 fabric 添加信号处理程序以捕获 SIGINT 并调用 SendReqSignal() 将其发送到远程进程。

或者您可能只是用 stty 调用包装 fabric 以将 INTR 字符更改为其他字符,然后再将其更改回来。

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

关于python - 使用 Fabric 的远程交互 shell 被 CTRL-C 杀死,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9652296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com