I am taking backup of different network devices daily using paramiko. Each device takes different time interval to login in to the device and also take different time to complete each command. So if I keep time.sleep() with a static time value sometimes it is more time to wait and sometimes it is very less to wait. So how I can I write a program to wait until the first command execute and go for next one, irrespective time.sleep value.
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, port='22', username=usr_name, password=pwd)
connection = ssh.invoke_shell()
connection.send("\n")
time.sleep(14)
connection.send("enable\n")
time.sleep(3)
connection.send("%s\n" %(pwd))
time.sleep(1)
connection.send("terminal length 0\n")
time.sleep(1)
connection.send("sh int status | ex (trunk|routed)\n")