I have a Raspberry Pi 2 running as a server in my home. Sometimes, my internet access goes away and when it goes back I have to reboot my RPi2 because the ethernet interface has no link to the modem.
In order to fix the issue, I decided to write a script that pings my modem and router, and if one of them is turned off it'll restart the ethernet interface. I setup a timer to run it every 10 minutes, however, it's not working as expected (while the same script runs just fine in a Debian server in my home, using a cronjob). Here's the script:
$this->bbcode_second_pass_code('', '#!/bin/bash
MODEM_IP="192.168.1.1"
ROUTER_IP="192.168.0.1"
INTERFACE="eth0"
# Check if we are running the script as root
if [[ $(id -u) -ne 0 ]]; then
echo "Please execute this script as root."
exit 1
fi
# Ping router 5 times to check if it's up; then ping modem 5 times to check if it's up.
# If any of these "tests" fail, we restart the interface.
if [[ ! $(ping -c 5 $ROUTER_IP 2>&1 /dev/null | echo $?) -eq 0 ]] && [[ ! $(ping -c 5 $MODEM_IP 2>&1 /dev/null | echo $?) -eq 0 ]]; then
ifconfig $INTERFACE down
ifconfig $INTERFACE up
fi')
What I'd like to know is why it isn't working. Could it be the timer interval that is too big?