Chris D Norton
TVWBB Member
I saw this post from Steve_M and have no idea how to implement this into the interface.
I don’t want to mess this bad boy up and wanted to know if someone can baby step me through how to get this going. Ultimately I believe this checks my WiFi and reboots the meter if no connection?
Save the script below as /mnt/mmcblk0p4/net-watchdog.sh and make sure it's executable
Add a cron job to call the script every 10 minutes.
Code:
*/10 * * * * /mnt/mmcblk0p4/net-watchdog.sh
What it does: Pings the gateway ( your wireless router ) and checks for the message "1 packets received". If that's not found, it will first attempt to restart the networking stack on the RasPi. It will then wait 2 minutes for things to stabilize and check again. If it still doesn't get a response, it will reboot the RasPi and that should get things sorted out.
Code:
#!/bin/sh
checkgw () {
ping_gw=$(netstat -nr | grep "UG" | awk '{print $2}' | xargs ping -q -w 1 -c 1 | grep "1 packets received")
result=$?
}
checkgw
if [ "$result" -ge 1 ]
then
logger -p user.alert "Restarting network"
/etc/init.d/network reload
sleep 120
checkgw
if [ "$result" -ge 1 ]
then
logger -p user.alert "Rebooting"
/sbin/reboot
fi
fi
I don’t want to mess this bad boy up and wanted to know if someone can baby step me through how to get this going. Ultimately I believe this checks my WiFi and reboots the meter if no connection?
Save the script below as /mnt/mmcblk0p4/net-watchdog.sh and make sure it's executable
Add a cron job to call the script every 10 minutes.
Code:
*/10 * * * * /mnt/mmcblk0p4/net-watchdog.sh
What it does: Pings the gateway ( your wireless router ) and checks for the message "1 packets received". If that's not found, it will first attempt to restart the networking stack on the RasPi. It will then wait 2 minutes for things to stabilize and check again. If it still doesn't get a response, it will reboot the RasPi and that should get things sorted out.
Code:
#!/bin/sh
checkgw () {
ping_gw=$(netstat -nr | grep "UG" | awk '{print $2}' | xargs ping -q -w 1 -c 1 | grep "1 packets received")
result=$?
}
checkgw
if [ "$result" -ge 1 ]
then
logger -p user.alert "Restarting network"
/etc/init.d/network reload
sleep 120
checkgw
if [ "$result" -ge 1 ]
then
logger -p user.alert "Rebooting"
/sbin/reboot
fi
fi