I wrote this badly hacked script to try an achieve this result.
Code: Select all
#!/bin/sh
IP=$(ifconfig "$(ls -1 /sys/class/net | grep eth | head -n 1)" | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1)
clear
while true; do
ping -c 1 64.233.161.99 >> /dev/null
if [ $? -eq 1 ] ; then
echo "oh no...no google!" ;
echo "Attempting Reconection..."
# try to reconnect
killall dhcpcd
sleep 1
dhcpcd -t 5 eth0
sleep 5
IP=$(ifconfig "$(ls -1 /sys/class/net | grep eth | head -n 1)" | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1)
if [ "$IP" != "" ]; then
echo "We have an ip address...good! :D "
echo "new ip address is:-"
echo $IP
sleep 2
clear
fi
else
echo "google found :D" ;
echo $IP
fi
sleep 2
clear
done
Could this script be improved, or is there a different/better way of achieving the same result?