You are not logged in.

#1 2008-09-10 13:16:35

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

[Help]Ping Exit Status

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


Website - Blog - arch-home
Arch User since March 2005

Offline

#2 2008-09-10 15:04:30

filou.linux
Member
From: Zurich
Registered: 2008-04-17
Posts: 87

Re: [Help]Ping Exit Status

Hi, could you please post your script... it'd be easier to see what exactly you want to accomplish.

Offline

#3 2008-09-10 21:39:14

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Re: [Help]Ping Exit Status

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
fi

And the problem is that sometimes I lose the first ping


Website - Blog - arch-home
Arch User since March 2005

Offline

#4 2008-09-11 02:01:41

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: [Help]Ping Exit Status

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
fi

Offline

#5 2008-09-15 22:30:12

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Re: [Help]Ping Exit Status

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


Website - Blog - arch-home
Arch User since March 2005

Offline

#6 2008-09-16 05:30:42

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

Re: [Help]Ping Exit Status

Could you do a tight loop of 4 pings, and set a flag to 1 if any of them returns true?

Offline

Board footer

Powered by FluxBB