I'm trying to perform backup using Paramiko. When backup occurs I let script sleep for 240 seconds hoping it is complete however sometimes this may take longer than this. Is there anyway I can use a loop to keep checking every 20 seconds to see if such keywords such as "backup complete" exist is the output variable.
import datetime, time
from time import sleep
from Tkinter import *
import paramiko
from paramiko_expect import SSHClientInteraction
def backup():
prompt = 'root@servername user'
try:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=server, username=user, password=pass)
interact = SSHClientInteraction(client, timeout=10, display=True)
except paramiko.AuthenticationException:
print("Authentication failed, please verify your credentials: %s")
except paramiko.SSHException as sshException:
print("Unable to establish SSH connection: %s" % sshException)
except paramiko.BadHostKeyException as badHostKeyException:
print("Unable to verify server's host key: %s" % badHostKeyException)
except Exception as e:
print(e.args)
interact.send('su')
interact.expect("Password:")
interact.send("supassword")
interact.expect(prompt)
interact.send("who")
interact.expect(prompt)
cmd_output_who = interact.current_output_clean
print cmd_output_who