Due to irregular but daily powerfailures, I loose my routers IP number from time to time. The only way to get my internet to work again, is to "Reconnect" on the status page of the router. Not being there the whole time means that reguarly the downloads take a long unwanted pause.
What I have been looking for is a little program that will check every e.g. 10 minutes to see if I still ping the gateway of my ISP. If not, then renew the IP address. In windows, renewing the IP address is as simple as "ipconfig renew", but that doesn't work on our router.
Did some searching on the internet and see the ifup and ifdown commands, but those don't work.
Then I figured out that our beloved router uses udhcpc program. I've found this page about it: http://www.penguin-soft.com/penguin/man/8/udhcpc.html
Did some reading and testing, but when I do "udhcpc -i eth0", I get a few errors about missing scripts. So, not much luck yet.
With a bit of searching on the internet, I've found & partically created the script below. I don't know if other people have the same problem with loosing their IP address, then it might be good to include it in the "standard" KC build?
Can any of you help to improve this script and get it to work?
Many thanks in advance
Code:
#!/opt/bin/bash
DEST="addrres default gateway provider"
while [ : ]
do
if ping -q -w 2 -c 1 "$DEST" &>/dev/null # &> means both stdout+stderr
then # ping succeeded
then
flag="connected" # do nothing
fi
else # ping failed
result="$?" # to catch the return code if neede
then
reboot # Here should be a IP address renew instead of reboot
flag="disconnected" # if there is no power, then it will indicate as disconnected.
fi
fi
sleep 600 # sleep for 10 minutes
done