title: Linux bash script acting weird
body: <p>I have a simple bash script that is suppose to monitor if mysql is up or down. If it is down, i want to also stop HAProxy from running. Below is my simple bash script:</p>
  
  <pre><code>#!/bin/bash
  
  nc -z 127.0.0.1 3306
  rt_val=$?
  msg=$(sudo service haproxy stop);
  if [ $rt_val != 0 ]; then
      eval $msg
      exit 3
  else
      exit 0
  fi
  </code></pre>
  
  <p>The MySQL running or not part is working just fine. It is the stopping HAProxy part that seems to have an issue. What is happening is that HAProxy stops when mysql stops. But when i fire up MySQL and also HAProxy, it seems like the script continues to stop HAProxy even if MySQL is up and running.</p>