а вот на 3 канала переделано! но теперь без ошибок ;))#!/bin/sh
PATH="/sbin:/usr/bin"
ISP1="*.*.*.*"
ISP2="*.*.*.*"
ISP3="*.*.*.*"
OVER_ISP1="*.*.*.*"
OVER_ISP2="*.*.*.*"
OVER_ISP3="*.*.*.*"
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
netstat -nr | grep ${OVER_ISP3} >/dev/null 2>&1
if [ $? != 0 ]; then
echo "Add static route to ${OVER_ISP3} via ${ISP3}"
route add ${OVER_ISP3} ${ISP3} -static
fi
current_now=`netstat -nr | grep default | awk '{print $2}'`
echo -n "ping ISP1:"
ping -c 2 ${OVER_ISP1} >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo " [OK]"
ISP1_stat=0
else
echo " [FAILED]"
ISP1_stat=1
fi
echo -n "ISP2:"
ping -c 1 ${OVER_ISP2} >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo " [OK]"
ISP2_stat=0
else
echo " [FAILED]"
ISP2_stat=1
fi
echo -n "ping ISP3:"
ping -c 1 ${OVER_ISP3} >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo " [OK]"
ISP3_stat=0
else
echo " [FAILED]"
ISP3_stat=1
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}
fi
if [ ${ISP1_stat} -eq 1 -a ${ISP2_stat} -eq 1 -a ${ISP3_stat} -eq 0 -a ${current_now} != ${ISP3} ]; then
echo "ISP1 ISP2 suck"
route delete default
route add default ${ISP3}
fi
if [ ${ISP1_stat} -eq 0 -a ${current_now} != ${ISP1} ]; then
echo "Back to ISP1"
route delete default
route add default ${ISP1}
fi