title: if within for within while loop multiple condition and timer python
body: <p>i want to read (repeatedly) each line of the output command if condition match print line if not keep repeat the loop till timeout and print the current output or a message</p>
  
  <p>it keeps looping in both cases print line or timeup</p>
  
  <p>I want to just print the line once or timeup once if timeout and within the max_time_allowed keep trying the previous command because it may come up after some seconds</p>
  
  <pre><code>#Import ConncetHandler feature from netmiko
  from netmiko import ConnectHandler
  import time
  import re
  import sys
  import subprocess
  import os
  #Devices Details
  
  iosv_l2_s1 = {
      'device_type': 'cisco_ios',
      'ip': '1.1.1.1',
      'username': 'sdf',
      'password': 'ss',
  }
  
  #SSH to the below devices
  net_connect = ConnectHandler(**iosv_l2_s1)
  #Apply commands
  output = net_connect.send_command('show interface')
  max_time_allowed = 15
  start = time.time()
  
  while True:
      for line in output.split(os.linesep):
          if re.search(("(?=.*FUlL|2way)(?=.*192.168.0.4)"),line , re.I):
              print line
              start = time.time()
              time.sleep(2)
          elif (time.time() - start) &gt; max_time_allowed:
              print ("timeup")
  
  net_connect.disconnect()
  </code></pre>