Server up script - ping check

This silly little script checks if a host responds to initially 3 and then 5 icmp packets, if all fail then it sends an SMS using clickatell once again...
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin

if ifconfig | grep ppp0 > /dev/null
then
PKT_LOSS=`ping -c 3 xxx.xxx.xxx.xxx | grep transmitted | awk '{print $6}'`
PERCENT=`echo ${PKT_LOSS%%%}`
if [ $PERCENT = "100" ]
then
PKT_LOSS=`ping -c 5 xxx.xxx.xxx.xxx | grep transmitted | awk '{print $6}'`
PERCENT=`echo ${PKT_LOSS%%%}`
if [ $PERCENT = "100" ]
then
wget "http://api.clickatell.com/http/auth?api_id=yourapi_id&user=usrname&password=passwd" -O /tmp/sessionid -q
# Create session and save to /tmp/sessionid
sessionid=`cat /tmp/sessionid | awk '{print $2}'`
# use only the session id for the variable
smssend clickatell.sms $sessionid usrname passwd yourapi_id "SystemAlert" phone_No "Server not responding"
# send sms
else
echo "System Responding"
else
echo "System Responding"
fi
else
#yes I have a speedtouch STILL!
pppd call speedtch > /dev/null
#bandwith QoS thingy nothing important...
bandwith
fi

For the smssend part to work you will need the info from this post.

Thank you for playing :)

Popular Posts