相关疑难解决方法(0)

Paramiko和exec_command - 杀死远程进程?

我正在将Paramiko用于tail -f远程服务器上的文件.

以前,我们正在运行此通道ssh -t,但事实证明这种情况很脆弱,并且-t导致我们的远程调度系统出现问题.

我的问题是当脚本捕获SIGINT时如何杀死尾巴?

我的脚本(基于python paramiko模块中长期运行的ssh命令(以及如何结束它们))

#!/usr/bin/env python2
import paramiko
import select

client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect('someserver', username='victorhooi', password='blahblah')
transport = client.get_transport()
channel = transport.open_session()

channel.exec_command("tail -f /home/victorhooi/macbeth.txt")
while True:
    try:
        rl, wl, xl = select.select([channel],[],[],0.0)
        if len(rl) > 0:
            # Must be stdout
            print channel.recv(1024)
    except KeyboardInterrupt:
        print("Caught control-C")
        client.close()
        channel.close()
        exit(0)
Run Code Online (Sandbox Code Playgroud)

该脚本Ctrl-C成功捕获了我的结尾.但是,它使tail -f进程在远程系统上运行.

client.close()和channel.close()似乎都没有终止它.

我可以在except块中发出什么命令来杀死它?

远程服务器正在运行Solaris 10.

python ssh signals solaris paramiko

13
推荐指数
3
解决办法
2万
查看次数

Python Paramiko将CTRL + C发送到ssh shell

我正在使用Paramiko调用shell,以便通过ssh连接使用CLI.这个CLI的问题是如果我不使用CTRL + C专门关闭它,程序将无法在不重新启动系统的情况下再次打开.

我尝试过以下命令:

SSH.send("^C\n")
SSH.send("\x003")
Run Code Online (Sandbox Code Playgroud)

还有另一种方法可以称呼这些吗?再次,我已经建立了一个SSH连接使用paramiko.SSHClient()然后调用一个shell使用ssh.invoke_shell(),现在我需要发送CTRL + C到该shell关闭shell(而不是ssh连接)

python ssh shell paramiko

4
推荐指数
1
解决办法
6427
查看次数

标签 统计

paramiko ×2

python ×2

ssh ×2

shell ×1

signals ×1

solaris ×1