2017-04-19 97 views
0

此问题与Taking the input from auto-execute user login using ssh execute command有关,我尝试采用另一种方法解决当前问题。从远程卡住的paramiko ssh注销

由于paramiko循环永远在等待用户输入命令。我无法杀死,有任何进展或做任何事情。

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),并杀死这个remoteuser表。

在根:

$ skill -KILL -u remoteuser 

我尝试使用线程,但由于它无法处理。它未能执行下一个线程。

thread1 = threading.Thread(target=remoteuser_stuckfreeze) 
thread2 = threading.Thread(target=roottokillremoteuser) 
thread1.start() 
thread2.start() 
thread1.join() 
thread2.join() 

谢谢。

回答

0

我结束了使用fabric

from fabric.tasks import execute 
from fabric.api import run, settings, env 

def remoteuser_login(self): 
    env.user = 'remoteuser' 
    env.password = 'remotepassword' 
    with settings(prompts={'>': 'q\n'}): 
     run('exit') 

,并执行该

execute(remoteuser_login, host='ipaddress') 

而且到hightlight,面料也有命令超时,此时我们可以设置这个,如果坚持从远程退出。

--command超时= N

http://docs.fabfile.org/en/1.13/usage/fab.html

0

使用替代parallel-ssh

from pssh import ParallelSSHClient 
client = ParallelSSHClient(['myhost'], user='remoteuser', 
          password='remotepassword') 
output = client.run_command(<..>) 
# Can send data using stdin channel if needed 
# output.stdin.write('write on user prompt\n') 
# output.stdin.flush() 
stdout = list(output.stdout) 

有一个channel_timeout设置不活动的N秒后超时,等效的命令超时。

提出一个不同的paramiko使用库作为织物是我的和其他经验非常错误。