当前位置:   article > 正文

4G,pppd守护进行,断线重连,掉线重连_4g断线重连脚本

4g断线重连脚本

使用脚本,即可实现。

  1. #!/bin/bash
  2. #exit 0
  3. #echo "4g test"
  4. #ls /dev/ttyU*
  5. #cat /dev/ttyUSB2 &
  6. #echo -en "AT\r\n" > /dev/ttyUSB2
  7. #killall cat
  8. #exit 0
  9. echo "4g pppd"
  10. count=0
  11. #sleep 5
  12. #procedure='pppd'
  13. if [ "$(ps |grep "pppd call" |grep -v grep |awk '{print $1}')" ]; then
  14. killall pppd #结束PPPD进程
  15. fi
  16. for ((i=0; i<15; i++))
  17. do
  18. sleep 1
  19. if [ -f "/sys/class/gpio/gpio65/value" ]; then
  20. break
  21. else
  22. echo 65 > /sys/class/gpio/export
  23. fi
  24. done
  25. echo high > /sys/class/gpio/gpio65/direction
  26. fun_check_usb(){
  27. countCheckUSB=0
  28. while true
  29. do
  30. usleep 500000
  31. ret=`ls /dev/ttyUSB*`
  32. if [ "$ret" ]; then
  33. echo $ret
  34. break
  35. fi
  36. let countCheckUSB++
  37. if [ $countCheckUSB -gt 35 ]; then
  38. reboot
  39. exit 0
  40. fi
  41. done
  42. }
  43. fun_check_usb
  44. #"/sys/class/net/eth0"
  45. #ifconfig eth0 down
  46. #ifconfig eth1 down
  47. #rm /etc/resolv.conf
  48. #ln -s /etc/ppp/resolv.conf /etc/resolv.conf
  49. cp /etc/ppp/resolv.conf /etc/resolv.conf
  50. pppd call wcdma-ec20 >/dev/null 2>&1 &
  51. sleep 12 #等待12秒
  52. fun_wait_ppp0(){
  53. countWait=0
  54. while true
  55. do
  56. usleep 500000
  57. if [ "$(ifconfig |grep ppp0)" ]; then
  58. break
  59. fi
  60. let countWait++
  61. echo "pppd countWait=$countWait"
  62. if [ $countWait -gt 30 ]; then
  63. date
  64. killall pppd #结束PPPD进程
  65. echo "ppp0 is not existed"
  66. if [ $count -lt 15 ]; then
  67. count=15
  68. fi
  69. break
  70. #reboot
  71. #exit 0
  72. fi
  73. done
  74. }
  75. fun_wait_ppp0
  76. fun_route(){
  77. if [ ! "$(route -e |grep default |grep ppp0 |awk '{print $1}')" ]; then
  78. if [ "$(ifconfig |grep ppp0)" ]; then
  79. route del default
  80. route add default dev ppp0
  81. fi
  82. fi
  83. }
  84. fun_route
  85. #---auto ppp---
  86. dns1="8.8.8.8"
  87. dns2="114.114.114.114"
  88. sleep 12 #等待12秒
  89. while true
  90. do
  91. ping -s 1 -c 5 $dns1 >/dev/null 2>&1 #去PING第一个DNS
  92. if [ "$?" != "0" ] #假如PING不通
  93. then
  94. fun_route
  95. ping -s 1 -c 2 $dns2 >/dev/null 2>&1 #去PING第二个DNS
  96. if [ "$?" != "0" ]
  97. then
  98. date
  99. killall pppd #结束PPPD进程
  100. let count++
  101. echo "pppd count=$count"
  102. if [ $count -gt 30 ]; then
  103. reboot
  104. exit 0
  105. elif [ $count -gt 15 ]; then
  106. echo 0 > /sys/class/gpio/gpio65/value
  107. usleep 500000
  108. echo 1 > /sys/class/gpio/gpio65/value
  109. #ttyUSB* is existed about 10 second
  110. #sleep 12 #等待12秒
  111. fi
  112. sleep 12 #等待12秒
  113. fun_check_usb
  114. #ifconfig eth0 down
  115. #ifconfig eth1 down
  116. #cp /etc/ppp/resolv.conf /etc/resolv.conf
  117. pppd call wcdma-ec20 >/dev/null 2>&1 & #再去拨号
  118. sleep 12 #等待12秒
  119. fun_wait_ppp0
  120. fun_route
  121. sleep 5
  122. else
  123. count=0
  124. sleep 60 #如果是PING  DNS2通的话就直接等待5秒
  125. fi
  126. else
  127. count=0
  128. sleep 120 #如果是PING  DNS1通的话就直接等待5秒(一般要设置多长时间去PING请改这里)
  129. fi
  130. done

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/170785
推荐阅读
相关标签
  

闽ICP备14008679号