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 :
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
@vgaetera -- Can you help? There's so much which needs fixing in the post above.
@tmomas -- despite the Vladislav's efforts to make the script presentable, do we really want something which will keep filling persistent memory in the wiki?
I don't like that text in the wiki at all. I could understand logging the failures once they happen (just before the device is then rebooted), but logging each success every 15 minutes?
The wiki section is also strange, because it mixes the actual script with the wrapper script that creates the actual script. That has apparently confused also batsam. (it also talks about "bash script", although bash is just one non-standard alternative and the actual script has normal /bin/sh shebang)
I have no idea why the author of the script decided to utilize persistent logging.
In addition, there are multiple reasons for missing connectivity and reboot may not even help to restore it, and even if it helps, it may not be the best solution.
Be aware that if the default routing is set to OpenVPN tunnel, network_get_gateway may return empty/0.0.0.0 on a working connection. I believe it's also the case with the WG as well.
I think we should stop beating the dead horse, because:
reboot doesn't necessarily help
there's already a watchcat package as @LGA1150 mentioned
I suggest the wiki page is modified to mention watchcat instead of the custom script.