You are not logged in.
Pages: 1
Hello.
I am trying to ping different gateways to determine what ip address to use (virtual machine). The problem I'm having is that out of 4 pings, 1 ping fails and the other 3 succeeds. Thus exit status returns 1.
I need to return a good exit status (0), if I am receiving any type of ping. How can I go about doing that?
Thanks
Offline
Hi, could you please post your script... it'd be easier to see what exactly you want to accomplish.
Offline
I don't have access to the machine with the script on it now but it basically like this
ifconfig eth0 10.1.20.6 netmask 255.255.255.224
ping -c 4 -w 4 10.1.20.1
if [ $? == 0 ]; then
echo "Success Connected with Home"
route add default gw 10.1.20.1
exit 0
fi
ifconfig eth0 10.25.11.100 netmask 255.255.248
ping -c 4 -w 4 10.25.11.1
if [ $? == 0 ]; then
echo "Success Connected with School"
route add default gw 10.25.11.1
exit 0
fiAnd the problem is that sometimes I lose the first ping
Offline
Could you do something like:
PING_RESULT=`ping -c 4 -w 4 10.1.20.1 | grep 'bytes from'`
if [ -z "$PING_RESULT" ] ; then
# FAIL
else
# GOOD
fiOffline
Thanks, that sort off worked, let me on the right track though.
Ping returns the bytes form line even when all pings fail, but was able to get the successful ping number and compare it to see if it was greater than 0.
thanks again
Offline
Could you do a tight loop of 4 pings, and set a flag to 1 if any of them returns true?
- "Cryptographically secure linear feedback based shift registers" -- a phrase that'll get any party started.
- My AUR packages.
- I use i3 on my i7.
Offline
Pages: 1