2017-04-19 24 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

代替コマンド・タイムアウトの同等の非アクティブのN秒後にタイムアウトするchannel_timeout設定は、あり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) 

を使用して。

ライブラリを使用して別のparamikoを使用すると、Fabricは私の経験や他の経験では非常にバグです。

関連する問題