title: Testing multiple unix server Connectivity using ping command and send mail the hostname/ipaddress of the servers if any hosts are unreachable
body: <p>Testing multiple unix server Connectivity using ping command and send mail the hostname/ip-address of the servers if any hosts are unreachable</p>
  
  <p>There is file <code>host.txt</code> which contain the list of the servers we want to ping 
  for e.g </p>
  
  <pre><code>www.abc.domain01.com
  www.abc.domain02.com
  www.abc.domain03.com
  www.abc.domain04.com 
  </code></pre>
  
  <p>in this case i'm considering there are total four servers ; but it can be 100 servers 
  i know how to check the connectivity of multiple servers but i don't know how to get the mail if particular server(s) is unreachable 
  MY CODE IS </p>
  
  <pre><code>email=XXXXXXXXXXXXX@domain.com
  for i in $(cat host.txt)
  do 
        ping -c4 $i 
  
  if [ $? -ne 0 ]
  then 
  
  echo "$i is unreachable"|mail -s "ping alert" $email 
      fi
  done 
  </code></pre>
  
  <p>suppose server <code>www.abc.domain01.com</code> is unreachable so i want see the output in my mail like <code>www.abc.domain01.com</code> </p>