目录

[TOC]


一、一键部署

二、手动部署

  1. 将脚本放到openwrt中,比如放到/mnt/local/scripts/目录下
vim /mnt/local/scripts/Detect_Ipv6_and_Reboot.sh

2.将如下脚本复制到/mnt/local/scripts/Detect_Ipv6_and_Reboot.sh

#!/bin/bash

# 定义变量
url="http://6.ipw.cn"
timeout=10
max_failures=3
failures=0

# 循环检测
while true; do
    # 发送请求并获取状态码
    response=$(curl -sL --connect-timeout $timeout -w "%{http_code}" $url -o /dev/null)
    # 判断状态码是否正常
    if [ "$response" != "200" ]; then
        echo "$(date): 请求失败,状态码为 $response" >> /mnt/local/opwnert/system.log
        failures=$((failures + 1))
    else
        # echo "$(date): 请求成功"
        failures=0
    fi

    # 如果连续失败次数达到阈值,则重启系统
    if [ $failures -ge $max_failures ]; then
        echo "$(date): 连续 $max_failures 次请求失败,准备重启系统..." >> /mnt/local/opwnert/system.log
        # sudo reboot
    fi

    # 等待一分钟后再进行下一次检测
    sleep 60

done

3.给脚本添加执行权限

chmod +x /mnt/local/scripts/Detect_Ipv6_and_Reboot.sh

4.将脚本添加到/etc/rc.local中 exit 0 之前

vim /etc/rc.local
bash /mnt/local/scripts/Detect_Ipv6_and_Reboot.sh &

5.重启路由器

reboot
Last modification:April 22, 2023
V50%看看实力