【发布时间】:2017-09-15 02:53:07
【问题描述】:
这个问题与Taking the input from auto-execute user login using ssh execute command 有关,我尝试用另一种方法来解决我当前的问题。
由于 paramiko 循环永远在等待用户输入命令。我无法杀死、拥有 pid 或做任何事情来继续。
stdin, stdout, stderr = self.connection.exec_command(command)
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
alldata = stdout.channel.recv(1024)
rl, wl, xl = select.select([stdout.channel], [], [], 0.0)
if len(rl) > 0:
self.logger.info(stdout.channel.recv(1024), )
哪种方法,我尝试使用 paramiko 登录到其他用户(root)并杀死这个远程用户。
在根目录中:
$ skill -KILL -u remoteuser
我尝试使用线程,但由于它无法处理。执行下一个线程失败。
thread1 = threading.Thread(target=remoteuser_stuckfreeze)
thread2 = threading.Thread(target=roottokillremoteuser)
thread1.start()
thread2.start()
thread1.join()
thread2.join()
谢谢。
【问题讨论】:
标签: python multithreading ssh paramiko