找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 3800|回复: 42

[2019.11.16]分享个脚本,主要用来检测无线中继断线并重连[特别适用于原生openwrt]

[复制链接]
本帖最后由 fengchen 于 2019-11-16 14:07 编辑

[11.16]
只是ifconfig wlan0 down和up会导致默认路由丢失,修改了下脚本:

#!/bin/sh
GATEWAY='192.168.50.1'
PING_CNT=6
SLEEP_TIME=100

logger -t $0 "keepalive.sh is running ..."
sleep 60

while [ 1 ]
do
        OK_CNT=`ping -c $PING_CNT $GATEWAY 2> /dev/null | grep ttl -c`
        if [ $OK_CNT -eq 0 ] ; then
                ifdown wwan
                ifup wwan
                logger -t $0 "ifdown & ifup wwan"
                sleep 40

                OK_CNT=`ping -c $PING_CNT $GATEWAY 2> /dev/null | grep ttl -c`
                if [ $OK_CNT -eq 0 ] ; then
                        /etc/init.d/network restart
                        logger -t $0 "/etc/init.d/network restart"
                        sleep 60

                        OK_CNT=`ping -c $PING_CNT $GATEWAY 2> /dev/null | grep ttl -c`
                        if [ $OK_CNT -eq 0 ] ; then
                                logger -t $0 "rebooting ..."
                                reboot
                        fi
                fi
        fi
        
        sleep $SLEEP_TIME
done



---------------------------------------------------------------------------------------
[10.8]
修改了下脚本#!/bin/sh
GATEWAY='192.168.50.1'
PING_CNT=6
SLEEP_TIME=100

sleep 200

while [ 1 ]
do
        OK_CNT=`ping -c $PING_CNT $GATEWAY 2> /dev/null | grep ttl -c`
        if [ $OK_CNT -eq 0 ] ; then
                ifconfig wlan0 down
                ifconfig wlan0 up
                logger -t $0 "ifconfig wlan0 down & up"
                sleep 20
               
                OK_CNT=`ping -c $PING_CNT $GATEWAY 2> /dev/null | grep ttl -c`
                if [ $OK_CNT -eq 0 ] ; then
                        ifdown wwan
                        ifup wwan
                        logger -t $0 "ifdown & ifup wwan"
                        sleep 40

                        OK_CNT=`ping -c $PING_CNT $GATEWAY 2> /dev/null | grep ttl -c`
                        if [ $OK_CNT -eq 0 ] ; then
                                logger -t $0 "rebooting ..."
                                reboot
                        fi
                fi
        fi
        
        sleep $SLEEP_TIME
done

脚本最好放在/etc/config,在备份配置的时候会自动把这个文件夹内的文件打包



【9.25】
由于rc.local是由/etc/rc.d/S95done调用,里面如果有死循环会影响后面的初始化脚本
所以还是把这个脚本放进一个keepalive.sh文件,文件放在/root目录

system->startup->Local Startup填
  1. sh /root/keepalive.sh &
复制代码
======================================================================================
无线中继时,有时中继路由莫名其妙断线,找了很久没有找到合适的脚本,于是自己写了个脚本添加在system->startup->Local Startup
  1. #!/bin/sh
  2. GATEWAY='192.168.50.1'
  3. sleep 200

  4. while [ 1 ]
  5. do
  6.         PING=`ping -c 5 $GATEWAY 2> /dev/null | grep ttl`
  7.         if [ -z "$PING" ] ; then
  8.                 logger -t $0 "____Network has been broken____"
  9.                 /etc/init.d/network restart
  10.                 logger -t $0 "____Network has been restarted____"
  11.         fi
  12.         
  13.         sleep 100
  14. done
复制代码


sleep是以秒为单位

也试过用crontab定时任务,因为执行频率高每次都会刷一条log,很讨厌

如果还有其它启动脚本,可以把这个脚本放进一个keepalive.sh文件,文件放在/root目录
此处则填
  1. sh /root/keepalive.sh &
复制代码



我的恩山、我的无线 The best wifi forum is right here.
我用了这么多年op,都是可以自动重连的啊

点评

好吧,我改了  详情 回复 发表于 2019-9-24 20:39
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| | 显示全部楼层
wulishui 发表于 2019-9-24 20:18
我用了这么多年op,都是可以自动重连的啊

好吧,我改了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

是可以自动切换的吗!!!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

看看,字数补丁
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

老毛子有自动重连功能
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

学习学习,谢谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

谢谢分享!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

感谢感谢再感谢!
来自微站
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

一去不返
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

感谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

老大,本人小白正有此需求,但是你说的:system->startup->Local Startup填  。这个在哪找,我openwory文件里没找到,能再详细些吗?多谢!

点评

我用的英文菜单,中文的话大概是系统-启动-自启动脚本  详情 回复 发表于 2019-10-12 17:19
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

好的 看看   谢谢楼主 楼主辛苦
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

好的 看看   谢谢楼主 楼主辛苦
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

非常感谢楼主的分享!谢谢
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

欢迎大家光临恩山无线论坛上一条 /1 下一条

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-29 15:57

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表