You can download the contents of the networkmon.sh script from the downloads section or copy and paste it from here:

#Update the "HOSTS" line with as many domains or IP address you would 
#like this script to monitor, separate each with a space.
HOSTS="DOMAIN1 DOMAIN2 IPADDR3 IPADDR4"
# Modify "COUNT" to adjust the amount of pings that are sent
COUNT=1
for myHost in $HOSTS
do
  count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
  if [ $count -eq 0 ]; then
    # If 100% failed email the address below with the message contents of the file /root/mail/networkdown.txt
    echo "Host : $myHost is down (ping failed) at $(date)" | ssmtp EMAIL@ADDRESS < /root/mail/networkdown.txt
  fi
done

I save the above content in /scripts/networkmon.sh, but feel free to save it in a more suitable location for your needs.

Next you need to create the contents of /root/mail/networkdown.txt (again feel free to save this file in a different location and update the file path in the script portion above)

To: EMAIL@ADDRESS
From: sSMTPEMAIL@ADDRESS
Subject: ALERT! Network Down

This is a notice that the domain DOMAINNAME did not respond to the 10 minute check in.

Please look into the issue!

Thanks
Admin

The last step is to make a cron job to run this script every 10 minutes. I use Webmin to make cron jobs, I find it much easier that way. Please view the document "How to Setup a Cron Job" if you need further assistance.

Tagged: