Linux – script to check if IP address or addresses are reachable & send email notification if not

Edit the below script to suit your needs and add it to CRON, run every 15 minutes, every hour or whatever you need.

It will email you if any of your chosen ip addresses are offline

#!/bin/bash
# ip ping notification script by scunster
# add ip / hostnames separated by space
HOSTS="192.168.1.1 192.168.1.2 192.168.1.3"
# no ping request
COUNT=1
# email report
SUBJECT="Ping Failure Notice!"
EMAILID="your@email_address.co.uk"
for myHost in $HOSTS;
do
count=`ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }'`
if [ $count -eq 0 ]
then
echo "Host : $myHost is down (ping failed) at $(date)" | mail -s "$SUBJECT" $EMAILID
#else
#echo "Host : $myHost is up (ping passed) at $(date)" | mail -s "$SUBJECT" $EMAILID
fi
done
Print Friendly, PDF & Email

More Like This


Categories


Linux Web Hosting

Tags


  • Post a comment