我有一个脚本,在特定情况下需要在远程计算机上运行非常耗时的脚本。我目前这样做:
if specific_case:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('10.0.0.1', username='username', password='password')
stdin, stdout, stderr = client.exec_command('tmux new-session -d -s session_name \'python /home/username/flamethrower.py'\'')
现在 - 到目前为止一直很好..我怎么能在最初启动它的脚本中等待python /home/username/flamethrower.py
并且可能有简约的反馈?
运行在远程计算机上启动flamethrower.py
的脚本的计算机是Windows 8.1,运行flamethrower.py
的计算机是Debian wheezy。
伪编码:
[...] # as above
while not stdin, stdout, stderr = client.exec_command('tmux new-session -d -s session_name \'python /home/username/flamethrower.py'\''):
#while it's not done, print a dot every minute
sys.stdout.print('.')
sys.flush()
sleep(60)
答案 0 :(得分:2)
将远程脚本输出到某个日志文件,包括完成后,然后每隔一段时间轮询一次远程连接以获得完成输出,(并获取剩余的输出)。