Автоматическое переключение каналов скрипт Ubuntu/Linux/FreeBSD

ByDmitriy Altuhov

Автоматическое переключение каналов скрипт Ubuntu/Linux/FreeBSD

#!/bin/sh

GW1=123.123.123.1
IP1=123.123.123.5
GW2=ppp1000
IP2=234.234.234.234
seychas=`date “+%Y-%m-%d %H:%M:%S”`
TARGET=192.36.148.17
#echo “ok” > /tmp/testgw
#echo “<b>GW test</b>” | mail -s “GW Change” email@example.com
/sbin/route add -host $TARGET gw $GW1
/bin/ping -q -c 3 $TARGET > /dev/null 2>&1
PING1=$?
/sbin/route del -host $TARGET gw $GW1
if [ $PING1 != 0 ]; then
/sbin/route add -host $TARGET dev $GW2
/bin/ping -q -c 3 $TARGET > /dev/null 2>&1
PING2=$?
/sbin/route del -host $TARGET dev $GW2
              if [ $PING2 = 0 ]; then
#                       /bin/echo “OK1”
                      if [ ! -f /tmp/gw.changed ]; then
#                       /bin/echo “OK2” && /bin/echo “${seychas} router now ${GW2}” >> /var/log/chanel && touch /tmp/gw.changed
#                        /sbin/route del default
                      /sbin/ip route replace default dev $GW2 && /bin/echo “${seychas} router now ${GW2}” >> /var/log/chanel && touch /tmp/gw.changed
fi
fi
else
#                       /bin/echo “OK3”
                      if [ -f /tmp/gw.changed ]; then
#                       /bin/echo “OK4” && /bin/echo “${seychas} router now ${GW1}” >> /var/log/chanel && rm /tmp/gw.changed
#                        /sbin/route del default
                      /sbin/ip route replace default via $GW1 && /bin/echo “${seychas} router now ${GW1}” >> /var/log/chanel && rm /tmp/gw.changed
fi
fi

About the author

Dmitriy Altuhov administrator