Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. INTERVAL=5
  4. PACKETS=1
  5. HOST="8.8.4.4"
  6. WAN1=wan
  7. WAN2=3G
  8. USINGWAN=1;
  9. LOG="/root/failover.log"
  10.  
  11. echo "`date`: Failover script started." >> $LOG
  12. while sleep $INTERVAL
  13. do
  14. RET=`ping -w 2 -c $PACKETS $HOST 2>/dev/null | awk '/packets received/ {print $4}'`
  15. if [ "$RET" -ne "$PACKETS" ]; then # Do we get a ping return? No? Go ahead....
  16. if [ "$USINGWAN" = "1" ]; then # Switch from WAN to 3G
  17. if expr $VNS '<' $MAXMB 1>/dev/null; then
  18. ifup $WAN2
  19. USINGWAN=2
  20. echo "`date`: Changed active WAN port to 3G modem!" >> $LOG # Log it
  21. fi
  22. fi
  23. else
  24. if [ "$USINGWAN" = "2" ]; then # Switch from 3G to WAM
  25. ifdown $WAN2 # Shutdown WAN2
  26. ifup $WAN1 # Enable WAN1
  27. echo "nameserver 8.8.8.8" > /etc/resolv.conf
  28. USINGWAN=1
  29. echo "`date`: Changed active WAN port to DSL connection!" >> $LOG # Log it
  30. fi
  31. fi
  32. done;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement