Rexxer

Some tips for me and other

Internet channel reservation script

My script:

#!/bin/sh
PATH=”/bin:/sbin:/usr/bin”

#Main Provider Router
ISP1=”1.1.1.1″

#Second Provider Router
ISP2=”2.2.2.2″

#IF 2 channels don’t work – will be set it
DEFAULT_ISP=”1.1.1.1″

# IP’s for ping
OVER_ISP1=”1.1.1.1″
OVER_ISP2=”2.2.2.2″

# Local source IP’s
IP1=”myip1″
IP2=”myip2″

# Verify routes
#netstat -nr | grep ${OVER_ISP1} >/dev/null 2>&1
#if [ $? != 0 ]; then
#        echo “Add static route to ${OVER_ISP1} via ${ISP1}”
#        route add ${OVER_ISP1} ${ISP1} -static
#fi
#netstat -nr | grep ${OVER_ISP2} >/dev/null 2>&1
#if [ $? != 0 ]; then
# echo “Add static route to ${OVER_ISP2} via  ${ISP2}”
# route add ${OVER_ISP2} ${ISP2} -static
#fi
# What is work now
current_now=`netstat -nr | grep default | awk ‘{print $2}’`
# echo -n “ping over ISP1:”
ping -c 2 -S ${IP1} ${OVER_ISP1} >/dev/null 2>&1
if [ $? -eq 0 ]; then
#echo ” [OK]”
ISP1_stat=0
else
#echo ” [FAILED]”
ISP1_stat=1
mail -s “Main Internet-channel FAILED” root < /dev/null
fi
# echo -n “ping over ISP2:”
ping -c 1 -S ${IP2} ${OVER_ISP2} >/dev/null 2>&1
if [ $? -eq 0 ]; then
#echo ” [OK]”
ISP2_stat=0
if [ -f /tmp/isp2.tmp ]; then
rm /tmp/isp2.tmp
mail -s “Second Internet-channel RESTORED” root < /dev/null
fi;
else
#echo ” [FAILED]”
ISP2_stat=1
if [ -f /tmp/isp2.tmp ]; then
echo “still nothing” > /dev/null
else
mail -s “Second Internet-channel FAILED” root < /dev/null
echo “failed” > /tmp/isp2.tmp
fi
fi
if [ ${ISP1_stat} -eq 1 -a ${ISP2_stat} -eq 0 -a ${current_now} = ${ISP1} ]; then
#echo “ISP1 suck”
route delete default
route add default ${ISP2}
mail -s “Main Internet-channel FAILED – switching to Second” root < /dev/null
fi
if [ ${ISP1_stat} -eq 0 -a ${current_now} != ${ISP1} ]; then
#echo “Back to ISP1”
route delete default
route add default ${ISP1}
/usr/local/etc/racoon/setkey.conf
mail -s “Main Internet-channel OK – switching back to MAIN” root < /dev/null
fi

# Check IPSEC channel
ping -c 1 192.168.1.1 >/dev/null 2>&1
if [ $? -ne 0 ]; then
/usr/local/etc/racoon/setkey.conf > /dev/null
mail -s “IPSEC channel to DC is failed – restarting rules” root < /dev/null
fi

Leave a Reply