路由器每10分钟检测是否能ping通百度,如果不能就重连wan口的脚本

路由器每10分钟检测是否能ping通百度,如果不能,就重连wan口的脚本
用来应对学校的奇怪网络环境

#!/bin/sh

TARGET="www.baidu.com"
LOG_FILE="/tmp/check_wan.log"
MAX_SIZE=10240
CHECK_INTERVAL_FILE="/tmp/check_wan_last_check"
MIN_INTERVAL=600

current_time=$(date +%s)
if [ -f "$CHECK_INTERVAL_FILE" ]; then
    last_check_time=$(cat "$CHECK_INTERVAL_FILE")
else
    last_check_time=0
fi

time_diff=$((current_time - last_check_time))
if [ "$time_diff" -lt "$MIN_INTERVAL" ]; then
    echo "$(date): Skipping check. Last check was $time_diff seconds ago." >> "$LOG_FILE"
    exit 0
fi

echo "$current_time" > "$CHECK_INTERVAL_FILE"

if ! ping -c 3 -W 2 $TARGET >/dev/null 2>&1; then
    echo "$(date): Unable to reach $TARGET. Restarting WAN..." >> "$LOG_FILE"
    ifdown wan
    ifup wan
else
    echo "$(date): Network is OK." >> "$LOG_FILE"
fi

if [ -f "$LOG_FILE" ] && [ $(stat -c%s "$LOG_FILE") -gt $MAX_SIZE ]; then
    echo "$(date): Log file size exceeded. Clearing log file." > "$LOG_FILE"
fi
博客内容均系原创,未经允许严禁转载!
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇