#!/bin/bash # #Script to test network availability, and notify if the internet is down. # # #Written in jEdit by #Tony Dodd # #declare some variables #The following three ip variables should each contain a valid ip. checkip1="204.157.6.3" checkip2="205.177.13.2" checkip3="4.2.2.1" #This should be set to whatever the name for your private nic is privif="eth0" #Do not change this block test1="`fping $checkip1`\n" test2="`fping $checkip2`\n" test3="`fping $checkip3`" live1="" live2="" live3="" alive="" privip="`ifconfig $privif | head -2 | tail -1 | awk '{print $2}' | cut -d":" -f2`" #Set this to the e-mail address that notifications should go to addr="alerts@10.0.250.250" #Set this to the subject you want to appear on mails for problem nodes subject="Connectivity issues - `hostname -s` - $privip" #Set this to the content you want to appear on mails for problem nodes content="`hostname -s` - $privip - has connectivity issues Results: $test1 $test2 $test3" function test { #function to test the status of connectivity, and converts the output into a 1 or 0 value if [ "x`fping $checkip1 | awk '{print $3}'`" == "xalive" ] then live1=1 else live1=0 fi if [ "x`fping $checkip2 | awk '{print $3}'`" == "xalive" ] then live2=1 else live2=0 fi if [ "x`fping $checkip3 | awk '{print $3}'`" == "xalive" ] then live3=1 else live3=0 fi #adds output together to give a total value alive="$(( $live1 + $live2 + $live3 ))" } function result { #checks whether the total value is greater than 1, if it is, then things are likely ok. If not, there are issues. if [ $alive -ge 1 ] then exit 0 else alert fi } function alert { #sends the e-mail in case of issues printf "$content" | mail -s $subject $addr } test result alert