title: Nagios python script wait for execution
body: <p>I have this script which is run by nagios which checks the provider API if mitigation is enabled and reports back. I just copied an example from Nagios, I have no Python knowledge whatsoever. The problem is that sometimes the scripts needs 10 seconds to run and python just continues, so I need it to wait for execution.</p>
  
  <p>I found some examples using subprocess which were successful but I don't know how to add the .readline and .strip to the command.</p>
  
  <p>This is the original script:</p>
  
  <pre><code>#!/usr/bin/python
  import os, sys
  mitigation_enabled=os.popen("/usr/local/nagios/libexec/check_mitigation.py 
  | grep auto | awk '{print $2}'").readline().strip()
  
  if mitigation_enabled == "false":
      print "OK - Mitigation disabled." .format (mitigation_enabled)
      sys.exit(0)
  elif mitigation_enabled == "true":
      print "WARNING - Mitigation enabled." .format (mitigation_enabled)
      sys.exit(1)
  else:
      print "UKNOWN - mitigation status unknown." .format (mitigation_enabled)
      sys.exit(2)
  </code></pre>
  
  <p>So how do I make this with subprocess, wait for the execution of the external script and add the .readline and .strip values?</p>
  
  <p>Short question, how to make this work :)</p>
  
  <p>Thanks!</p>