title: Loop through a bunch of variables using a bash script
body: <p>I have 4 domains that I want to check in my cron every hour. It checks if a word exists, and if it doesn't it will reboot the machine. In my example below I have 4 domains I am checking, but how do I loop through these variables in an if statement without having to replicate this 4 times in my bash script. </p>
  
  <pre><code>#!/bin/bash
  
  webserv1="domain1.com"
  webserv2="domain2.com"
  webserv3="domain3.com"
  webserv4="domain4.com"
  
  Keyword="helloworld" # enter the keyword for test content
  
  
  if (curl -s "$webserv1" | grep "$keyword") 
  then
          echo " the website is working fine"
  else
          sudo reboot
  fi
  
  if (curl -s "$webserv2" | grep "$keyword") 
  then
          echo " the website is working fine"
  else
          sudo reboot
  fi
  
  if (curl -s "$webserv3" | grep "$keyword") 
  then
          echo " the website is working fine"
  else
          sudo reboot
  fi
  
  if (curl -s "$webserv4" | grep "$keyword") 
  then
          echo " the website is working fine"
  else
          sudo reboot
  fi
  </code></pre>