All pastes #166167 Raw Edit

Stuff

public shellscript v1 · immutable
·published 2006-09-10 16:48 UTC
rendered paste body
#!/bin/bash##Script to test network availability, and notify if the internet is down.###Written in jEdit by#Tony Dodd <tony@defenderhosting.com>##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 isprivif="eth0"#Do not change this blocktest1="`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 toaddr="alerts@10.0.250.250"#Set this to the subject you want to appear on mails for problem nodessubject="Connectivity issues - `hostname -s` - $privip"#Set this to the content you want to appear on mails for problem nodescontent="`hostname -s` - $privip - has connectivity issuesResults:$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=1else	live1=0fiif [ "x`fping $checkip2 | awk '{print $3}'`" == "xalive" ]then	live2=1else	live2=0fiif [ "x`fping $checkip3 | awk '{print $3}'`" == "xalive" ]then	live3=1else	live3=0fi#adds output together to give a total valuealive="$(( $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 0else	alertfi}function alert {	#sends the e-mail in case of issuesprintf "$content" | mail -s $subject $addr}testresultalert