美文网首页
猫盘掉ip修复

猫盘掉ip修复

作者: 鱼之不乐 | 来源:发表于2020-03-10 10:44 被阅读0次

    群晖计划任务里新增-触发的任务-用户自定义的脚本,按照下面设置,任务设置中填写代码如下:代码的作用是如果开机发现无法获得ip地址自动重启,直到获得I排为止。代码中的ip地址换为自己家里路由器的ip地址。

    #!/bin/bash

    dt=`date '+%d/%m/%Y %H:%M:%S'`

    sleep 60

    > /result.txt

    num=`ping -c20 192.168.2.1 | tail -2 | head -1 | cut -f 3 -d"," | cut -f 1 -d"%" | cut -f 2 -d" "`

    echo $num

    echo $?

    if [ $? -eq 0 -a $num -eq 0 ]; then

    echo "$dt ok" >> /result.txt

    else

    echo "$dt noip loss $num reboot" >> /result.txt

    reboot

    fi

    第二个方案也是一样 但是代码不一样 ip地址同样需要改为自己的路由器地址

    #!/bin/bash

    ROUTER_IP=192.168.1.1

    dt=`date '+%d/%m/%Y %H:%M:%S'`

    echo "$dt"

    sleep 60

    ping -c5 $ROUTER_IP

    if [ $? -eq 0 ]; then

    echo "$dt ok" >> /result.txt

    else

    echo "$dt noip reboot" >> /result.txt

    reboot

    fi

    相关文章

      网友评论

          本文标题:猫盘掉ip修复

          本文链接:https://www.haomeiwen.com/subject/nzwidhtx.html