pepowlan_watch

pepowlan_watchとはraspberry piの無線LAN又は有線LANの切断検出と回復をさせるものです

o 2015.8.26

o ファーストリリース

o 2015.9.9

o wlan0とeth0の両方の切断検出と回復機能追加

o 2015.9.20

o eth0 ダウン時の回復機能修正

  1. #!/bin/sh
  2. # licence GPLv2 ; this scripts designed by Yamauchi.Isamu 2015.8.26 update 2015.9.22
  3. # ping watch of wlan0 or eth0 fail for rasberry pi
  4. # pepowlan_watch
  5. STARTUP=/usr/src/pepolinux/startup.s
  6. [ ! -e $STARTUP ] && exit
  7. WORKDIR=/www/remote-hand/tmp
  8. MSLEEP=300123
  9. GATEWAY=`cat $STARTUP|awk '/GATEWAY/{gsub("\"","",$1);split($1,I,"=");print I[2]}'`
  10. [ -z $GATEWAY ] && exit
  11. PING_HOST=$GATEWAY
  12. WLAN_YES_NO=`ip link show wlan0 2>&1|awk 'BEGIN{WLAN="YES"};/does not exist/{WLAN="NO"};END{printf WLAN}'`
  13. ETH0_YES_NO=`ip link show eth0|awk 'BEGIN{ETH0="NO"};/state UP/{ETH0="YES"};END{printf ETH0}'`
  14. if [ $ETH0_YES_NO = "YES" ];then
  15. ETH0_IP=`cat $STARTUP|awk '/SET_ETH0/{gsub("\"","",$1);split($1,I,"=");printf I[2]}'`
  16. fi
  17. PING_LOG=$WORKDIR/.pepowlan_watch.log
  18. CMD=$WORKDIR/pepowlan_watch.pepocmd
  19. cat>$CMD<<END
  20. #!/bin/sh
  21. error() {
  22. [ -e $PING_LOG ] && rm -f $PING_LOG
  23. exit
  24. }
  25. trap error SIGTERM SIGHUP SIGKILL SIGINT
  26. while true
  27. do
  28. date +"%Y/%m/%d %T" > $PING_LOG
  29. if ! ping -c 1 $PING_HOST 2>&1 >>$PING_LOG; then
  30. msleep 1000
  31. if ! ping -c 1 $PING_HOST 2>&1 >> $PING_LOG; then
  32. if [ $WLAN_YES_NO = "YES" ];then
  33. ifdown wlan0
  34. ifup wlan0
  35. else
  36. ifdown eth0
  37. ifup eth0
  38. ifconfig eth0 $ETH0_IP
  39. ip route del default
  40. ip route add default via $GATEWAY
  41. fi
  42. fi
  43. fi
  44. msleep $MSLEEP
  45. done
  46. END