title: Bash Script to check for host
body: <p>I have a complicated script request that I am trying to figure out. Basically, I need a script that will check for certain conditions and depending on the outcome will run certain commands.</p>
  
  <p>So, I need it to check if $hostip is up and running. If it is running, I need it to check and see if $domain has same IP address as $domainip. If they match, script then ends. If they don't match, I need to run command "shutdown $hostip". Now, if it fails to find $domain, ie internet is down, then I need it to sleep for 6 hours and then try again. I want it to try 3 times and if still can't find domain after 18 hours, then run "shutdown $hostip".</p>
  
  <p>The goal above is to shutdown a server if the domain does not match the set IP or the internet is disconnected for 18 hours.</p>
  
  <p>I also need script to check the other side of things as well. So, if $hostip is not online, but $domain and $domainip do match, then power on server.</p>
  
  <p>These are my variables I have so far.</p>
  
  <pre><code>domain=google.com
  domainip=216.58.194.46
  hostip=192.168.1.1
  
  gatewayip=$(ping -q -c 1 -t 1 $domain | grep PING | sed -e "s/).*//" | sed -e "s/.*(//")
  </code></pre>