Heh, oops. That script would take up a lot of CPU cycles, forgot to chuck a sleep in there. You could add it to a cron list, or you could put a sleep line in there to only run the loop once every 5 mins.
Code:
#!/bin/bash
# this doesn't loop so it's good to add to a cron job
ping -c 1 -W 3 google.com
if [ $? -eq 1 ]; then
reboot
fi
Code:
#!/bin/bash
# this will run the check, wait for 300 seconds (5mins) and check again
while 1; do
ping -c 1 -W 3 google.com
if [ $? -eq 1 ]; then
reboot
fi
sleep 300
done
---------
Edit: Also, I'll just explain the ping command in case you're unsure what it does. Might be wasting my time or saving yours so you don't need to ask
That pings google.com once and gives it 3 seconds to respond. If you don't get a response in 3 seconds it assumes you have no connection and reboots. Change -W 3 to -W 5 or whatever if you want to increase the timeout. Run the ping a few times before running the script to see what the average response time is and then add like 5 seconds to that to allow for when you are connected but there is high load on the network or something