timp87

gwtest.sh

Aug 18th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.44 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Master ISP
  4. isp1_ip="85.143.163.113"
  5.  
  6. # Backup ISP
  7. isp2_ip="91.220.11.1"
  8.  
  9. is_set()
  10. {
  11.     ip="$1"
  12.     gw=`/usr/bin/netstat -rn -4 | /usr/bin/grep 'default' | /usr/bin/awk '{print $2}'`
  13.     test $gw = $ip
  14. }
  15.  
  16. set_gw()
  17. {
  18.     ip="$1"
  19.     /sbin/route change default $ip
  20. }
  21.  
  22. if /sbin/ping -c 10 -n -q $isp1_ip > /dev/null 2>&1
  23. then
  24.     is_set $isp1_ip || set_gw $isp1_ip
  25. else
  26.     is_set $isp2_ip || set_gw $isp2_ip
  27. fi
Advertisement
Add Comment
Please, Sign In to add comment