1.確認開啟crond服務烘贴,命令為:
/etc/init.d/cron enable
/etc/init.d/cron start
2.創(chuàng)建腳本文件
mkdir -p /root/home
vim /root/home/watchdog.sh
3.寫入腳本
#!/bin/sh
DATE=`date +%Y-%m-%d-%H:%M:%S`
tries=0
echo --- my_watchdog start ---
while [[ $tries -lt 5 ]]
do
if /bin/ping -c 1 114.114.114.114 >/dev/null
then
echo --- exit ---
exit 0
fi
tries=$((tries+1))
sleep 10
done
echo $DATE reboot >>my_watchdog.log
reboot
4.配置定時重啟任務轧叽,命令為:
0 3 * * * reboot
0 6 * * * sh /root/home/watchdog.sh
0 12 * * * sh /root/home/watchdog.sh
0 18 * * * sh /root/home/watchdog.sh
*/5 * * * * sh /root/home/watchdog.sh