[ask] disconnect and reconnect
i want to make a script to simulate the disconnect and connect form the web ui(status page) if my internet down.
every time my internet down, i need to disconnect and then connect the wan for it to work again.
i want to automate this by make a script that will try to ping to google every 10 minutes and if the result is rto, than the script will disconnect wan and than reconnect it.
what i found so far is this
Code:
#!/bin/bash
HOSTS="google.com"
COUNT=4
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
echo "Host : $myHost is down (ping failed) at $(date)"
fi
done
edit:
correct script
Code:
test=$(ping -c 2 google.com)
if [ -z $test ]; then
pid=$(ps | grep udhcpc | awk '{print$1}')
kill $pid
/sbin/udhcpc -i eth1 -p /var/run/udhcpc0.pid -bN61 -O33 -O121 -O249
fi
just need to add it to crontab -e and run crond