群暉計(jì)劃任務(wù)里新增-觸發(fā)的任務(wù)-用戶自定義的腳本兔簇,按照下面設(shè)置示惊,任務(wù)設(shè)置中填寫代碼如下:代碼的作用是如果開機(jī)發(fā)現(xiàn)無法獲得ip地址自動(dòng)重啟赴涵,直到獲得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
第二個(gè)方案也是一樣 但是代碼不一樣 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