Tested & it works
ЗЫ2: багрепорты приверствуюцо
Код: Выделить всё
#!/bin/bash
# interfaces
gen1us2k_if='eth0'
friday_if='eth1'
gen1us2k_ip='77.235.12.36'
kg_if='ppp0'
un_if='ppp1'
# text redactors
ifc='/sbin/ifconfig'
sed='/bin/sed'
g='/bin/grep'
unlim_if=`$ifc $un_if | $g addr: | $sed 's/.*addr:\([^ ]*\) .*/\1/'`
zone='/etc/bind/pri/warlegend.net.kg.all.incl'
# This function need to (re)configure internet interfaces
iface_configure (){
ret=$?
echo "Test for required interfaces"
# test interfaces
$ifc $gen1us2k_if
if [ "$ret" -ne "0" ]; then
/etc/init.d/net.eth0 start
if [ "$ret" -ne "0" ]; then
echo "Cannot configure interface, please do it by your hands"
exit [1]
fi
else
echo "Interface eth0 configured"
fi
$ifc $friday_if
if [ "$ret" -ne "0" ]; then
/etc/init.d/net.eth1 start
if [ "$ret" -ne "0" ]; then
echo "Cannot configure interface, please do it by your hands"
exit [1]
fi
else
echo "Interface eth1 configured"
fi
echo "Test completed sucessfully"
# configuring interfaces
pppd call gen1us2k
sleep 15s
if [ "`$ifc $kg_if | $g addr: | $sed 's/.*addr:\([^ ]*\) .*/\1/'`" -e "$gen1us2k_ip" ]; then
route add -net 77.235.0.0/19 dev $kg_if
route add -net 92.245.96.0/19 dev $kg_if
route add -net 109.201.160.0/19 dev $kg_if
route add -net 91.213.233.0/24 dev $kg_if
route add -host 217.29.21.21 dev $kg_if
fi
echo "ppp0 configured sucessfull, Start configuring next ppp interface"
pppd call friday
sleep 15s
if [ "`$ifc $un_if | $g addr: | $sed 's/.*addr:\([^ ]*\) .*/\1/'`" -ne "$gen1us2k_ip" ]; then
route del default dev $un_if
route add default dev $un_if
fi
echo "ppp1 configured sucessfull."
echo "Lets drink a beer ;-)"
}
# This function need to change zone options
change_ns (){
unlim_if=`$ifc $un_if | $g addr: | $sed 's/.*addr:\([^ ]*\) .*/\1/'`
echo "" > $zone
echo -e '@\t\tA\t' $unlim_if >> $zone
echo -e 'www\t\tA\t' $unlim_if >> $zone
echo -e '\tlisten-on { 127.0.0.1; 77.235.12.36; '$unlim_if';};' > /etc/bind/named.conf.incl
/etc/init.d/named restart
}
monitoring (){
while test 1
do
echo "Pinging ns server"
ping -c 3 77.235.14.2
ret="$?"
if [ "$ret" -ne "0" ]; then
echo `date` ", интернетама пизнец пришол О_о" >> /home/gen1us2k/epic_fail
killall pppd
sleep 5s
iface_configure
change_ns
fi
sleep 2m
done
}
case "$1" in
start) echo -n "Starting script"
monitoring
echo "..."
;;
*) echo "Usage: /etc/init.d/routes_inet start"
exit 1
;;
esac
exit 0