Operating System - HP-UX
1835065 Members
2181 Online
110073 Solutions
New Discussion

Re: ping return code in HP-UX 11.0

 
SOLVED
Go to solution
Erik Jagel
Occasional Contributor

ping return code in HP-UX 11.0

Does anyone know of a version of ping on HP-UX 11.0 that will return a non-zero return code if the pinged node is unreachable?

Thanks.
4 REPLIES 4
Lasse Knudsen
Esteemed Contributor

Re: ping return code in HP-UX 11.0

No I have never heard of one.

The only known use is to do something like this:

if ping -n 1 | grep '100% packet loss'
then
echo "host not responding"
else
echo "host is up"
fi
In a world without fences - who needs Gates ?
Victor BERRIDGE
Honored Contributor

Re: ping return code in HP-UX 11.0

I agree with Allan,
Write your own script using Allan's example:
#myping return a code
if /usr/sbin/ping $1 -n 1 | grep '100% packet loss'
then
#echo "host not responding"
exit 1
else
echo "host is up"
fi

Demo:
alnitak # myping draco
host is up
alnitak # echo $?
0
alnitak # myping triton
1 packets transmitted, 0 packets received, 100% packet loss
alnitak # echo $?
1


Regards
Victor
Andreas Voss
Honored Contributor
Solution

Re: ping return code in HP-UX 11.0

Hi,

i've found a C source for ping that will return 0 for success and 1 for failure, see attachment.
Compile: cc ping.c -o /usr/contrib/bin/myping
chown root /usr/contrib/bin/myping
chmod 4111 /usr/contrib/bin/myping

Regards
Erik Jagel
Occasional Contributor

Re: ping return code in HP-UX 11.0

Thank you Allen and Victor for the scripts. I had already written a script, but was looking for some source to create a binary. We're porting our Solaris scripts to HP-UX and needed a version of ping that acts like Solaris's.

Thanks Andreas - it turns out we located the source for ping yesterday and had it compiled and working. But I do appreciate your help!!!