I am trying to create a solution using Paramiko that allows to grab first line in output with matching criteria. I added while loop to wait until output will be available (some times command will be run for more them an hour). Currently I have:
- Connection to jump host
- Invoke shell and ssh to second host
- Run commands
- Wait (using while loop) to required output to be available.
- Save it as a str.
But I have problem with breaking while loop after required output is available.
Here is my code.
import paramiko
from time import sleep
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('jumphost', username='User', password='Passw')
sleep(2)
channel = ssh.invoke_shell()
channel.send('ssh secondHost\n')
sleep(2)
channel.send('Command1\n')
#sleep(2)
buff=''
while channel.recv_ready():
while not buff.endswith('$ '):
resp = channel.recv(9999)
for line in resp.split('\n'):
if line.startswith('Line1'):
print(line)
buff+=line
break
break
print 'buff', buff
ssh.close()