Operating System - HP-UX
1833043 Members
2706 Online
110049 Solutions
New Discussion

Re: ping return code on 11.i

 
Nicolas_17
Frequent Advisor

ping return code on 11.i

Hello,

I'm writing a monitoring script and I need the return code of a ping. The problem is, ping always returns 0 wether it's successfull or not! I found a patch that fixes this on a hp-ux 10.20 system: PHNE_24260. Now I need a similar patch on an 11.i system. I couldn't find anything on the table of equivalency. Has anybody found a solution for this?
8 REPLIES 8
Uday_S_Ankolekar
Honored Contributor

Re: ping return code on 11.i

This was the problem in 10.20 but 11, 11i already has fix to this and no need to have any patches.

man ping will show you the return code details in 11i

-USA..
Good Luck..
Sanjay_6
Honored Contributor

Re: ping return code on 11.i

Hi Nicolas,

I think path PHNE_27382 on 11i fixes that problem. the latest patch in that category is PHNE_31247.

http://www1.itrc.hp.com/service/patch/patchDetail.do?BC=patch.breadcrumb.main|patch.breadcrumb.pdb|patch.breadcrumb.search|&patchid=PHNE_31247&context=hpux:800:11:11

Hope this helps.

Regds
Sridhar Bhaskarla
Honored Contributor

Re: ping return code on 11.i

Hi,

My 11i does return various codes for various failures. My system is upto June 2004 level.

I believe the patch PHNE_27382 fixes it. I would see if there is any superceding patch to it and the dependencies.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Bill Hassell
Honored Contributor

Re: ping return code on 11.i

Actually, it's a bit more complicated. ping by default runs forever until signaled or if -n was specified, for that many tries. Since there is only one number returned, if 5 pings were sent, to which ping response should the return code apply? Or if 33% of the packets failed, should the return code be 33? The return codes are listed at the bottom of the man page and are for failures to get the IPaddress resolved or unrechable network (subnet error), etc. If the remote end does not respond, this is not part of the return code.

So you'll have to code the ping test to use a single test (-n 1) and I would also add the -m option to force a timneout, especially if several hosts are being tested in a script. NOTE: The ping options are quite position sensitive! -I and -v come before the hostname/IP, followed by -n and -m must be preceeded by -n first.


Bill Hassell, sysadmin
Nicolas_17
Frequent Advisor

Re: ping return code on 11.i

ok, I wasn't clear on what i meant about return codes. Ping does return a 0 if it succeeds and a 1 if it fails because it doesn't know the host I'm trying to reach.

But it returns 0 if the host exists in the /etc/hosts, even if it can't reach it. That's my problem.

example:

server:/# ping localhost -n 2
PING localhost: 64 byte packets
64 bytes from 127.0.0.1: icmp_seq=0. time=0. ms
64 bytes from 127.0.0.1: icmp_seq=1. time=0. ms

----localhost PING Statistics----
2 packets transmitted, 2 packets received, 0% packet loss
round-trip (ms) min/avg/max = 0/0/0

server:/# echo $?
0

Now if i try to ping an address that localhost knows but can't reach for unknown/irrelevant reasons:

server:/# ping whatever.hell.ca -n 2
PING whatever.hell.ca: 64 byte packets

----whatever.hell.ca PING Statistics----
2 packets transmitted, 0 packets received, 100% packet loss

server:/# echo $?
0

Notice the 0 again.

The reason i brought this to the forums is that i don't have that problem on linux. I'm transforming a script that works on a linux box so it can work on hp-ux. That's all.

Thanks for your help guys.
Sridhar Bhaskarla
Honored Contributor

Re: ping return code on 11.i

Hi Nicolas,

Yes. Your question was very well understood. The solution is the patch we mentioned. See for ex.,

$ /etc/ping bla -n 1
/etc/ping: unknown host bla
$ echo $?
1
$ /etc/ping somehost -n 1
PING somehost.mydomain.com: 64 byte packets

----somehost.mydomain.com PING Statistics----
1 packets transmitted, 0 packets received, 100% packet loss
$ echo $?
2
$ /etc/ping goodhost -n 1
PING goodhost.mydomain.com: 64 byte packets
64 bytes from xx.xx.xx.xx: icmp_seq=0. time=1. ms

---- goodhost.mydomain.com PING Statistics----
1 packets transmitted, 1 packets received, 0% packet loss
round-trip (ms) min/avg/max = 1/1/1
$ echo $?
0
$

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Nicolas_17
Frequent Advisor

Re: ping return code on 11.i

I see! so i guess i have an old version of ping. But that patch is serious stuff. I don't think it's worth it...just for this ping issue i mean. Anyways, i fixed my script in the meantime to work around the problem.
Nicolas_17
Frequent Advisor

Re: ping return code on 11.i

No reason the keep this thread alive...