Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- INTERVAL=5
- PACKETS=1
- HOST="8.8.4.4"
- WAN1=wan
- WAN2=3G
- USINGWAN=1;
- LOG="/root/failover.log"
- echo "`date`: Failover script started." >> $LOG
- while sleep $INTERVAL
- do
- RET=`ping -w 2 -c $PACKETS $HOST 2>/dev/null | awk '/packets received/ {print $4}'`
- if [ "$RET" -ne "$PACKETS" ]; then # Do we get a ping return? No? Go ahead....
- if [ "$USINGWAN" = "1" ]; then # Switch from WAN to 3G
- if expr $VNS '<' $MAXMB 1>/dev/null; then
- ifup $WAN2
- USINGWAN=2
- echo "`date`: Changed active WAN port to 3G modem!" >> $LOG # Log it
- fi
- fi
- else
- if [ "$USINGWAN" = "2" ]; then # Switch from 3G to WAM
- ifdown $WAN2 # Shutdown WAN2
- ifup $WAN1 # Enable WAN1
- echo "nameserver 8.8.8.8" > /etc/resolv.conf
- USINGWAN=1
- echo "`date`: Changed active WAN port to DSL connection!" >> $LOG # Log it
- fi
- fi
- done;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement