i'm trying to install and run the following script, but my knowledge in the matter isn't the best.
i made a file named pingRouterCheckReboot.sh on my pc with this content :
cat << "EOF" > /root/pingRouterCheckReboot.sh
#!/bin/sh
Prepare vars
DATE=$(date +%Y-%m-%d" "%H:%M:%S)
logFile="/root/pingRouterCheckReboot.log"
Ping and reboot if need
ping -c3 openwrt.org
if [ $? -eq 0 ]; then
echo "ok"
echo "${DATE} - ok" >> $logFile
else
echo "REBOOT"
echo "${DATE} - REBOOT" >> $logFile
reboot
fi
If the log file size is greater then 100KB (102400 bytes), then renew it.
logFileSize=$(wc -c "$logFile" | awk '{print $1}')
if [ $logFileSize -gt 102400 ]; then
echo "Size of $logFile = $logFileSize bytes."
echo "Renew the log file"
mv -f $logFile "${logFile}.bk"
fi
EOF
chmod +x /root/pingRouterCheckReboot.sh
then i copied pingRouterCheckReboot.sh file to the rooter root directory with winscp,
after that i pasted this :
Check every 15 minutes ping to google.com
If it is failed, then reboot the router
Note: To avoid infinite reboot loop, wait 70 seconds and touch a file in /etc
so clock will be set properly on reboot before cron starts.
0,15,30,45 * * * * sleep 70 && touch /etc/banner && /root/pingRouterCheckReboot.sh
to the openwrt router's Scheduled Tasks and pressed submit
original link
https://openwrt.org/docs/guide-user/base-system/cron
i have to idea if i've done anything right or wrong.
any help
thanks