I want to create a script for ddwrt that pings on 4 hosts to check whether internet is available or not. If out of 4 tests, one of the ping results comes true then assume internet is working otherwise No connection. At least one of the test needs to come true.
This is the script I've been working with.
#!/bin/sh
result=`ping -c 1 8.8.8.8 | grep -c from`
sleep 10
result+=`ping -c 1 www.google.com | grep -c from`
# I want the output from this command to add into result variable. For example, if result value is 0 then add the value of next ping command into 0, same with the rest of the commands. Is that possible?
sleep 10
result+=`ping -c 1 www.microsoft.com | grep -c from`
sleep 10
result+=`ping -c 1 www.youtube.com | grep -c from`
if [ $result -ge 1 ]
then
echo "Internet alright"
logger -t 'InternetCheck' 'Internet is Connected'
logger "ping $result"
else
logger -t 'InternetCheck' 'After many ping tests, the Internet is not working... will apply solution'
logger "ping $result"
fi
Although ddwrt already comes with watchdog, but i don't want router to reboot, instead i want to run commands at that moments to fix the issue. Please do give me any other suggestions.
Regards!
-woption, which makes ping more impatient, you could do this:if ping 1.2.3.4 -w 1; then echo ":-)"; else echo ":-("; fi.ping -c 1 www.google.com | grep -c fromintoresultvariable by adding it to it's current value. If the result holds 0 andping -c 1 www.google.com | grep -c fromoutputs 1 then final result value should be 1.pingwas designed for, and some hosts may simply ignore ping requests (even 8.8.8.8, a well-known nameserver, may change it's policy regarding ping at any time). Can you check for a default gateway/uplink? Interface status? (more...)