- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ping RETURN codes
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2002 01:55 AM
тАО07-11-2002 01:55 AM
a return code from ping is annoying one of my scripts..
Have a look:
pereal - /home/trsh # ping 1.2.3.4 -n 3
PING 1.2.3.4: 64 byte packets
----1.2.3.4 PING Statistics----
3 packets transmitted, 0 packets received, 100% packet loss
pereal - /home/trsh # echo $?
0
pereal - /home/trsh # what /etc/ping
/etc/ping:
PHNE_16158 ping.c $Revision: 1.8.119.5 $ $Date: 98/07/23 14:27:01 $
NET: Version: B.11.00 $Date: 97/10/15 10:44:23 $
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2002 02:01 AM
тАО07-11-2002 02:01 AM
Solutionping has always been non-existant in returing any error codes apart from 0. Instead scripts I use to see if something is pingable all grep for "100% packet loss" to see if it worked or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2002 02:18 AM
тАО07-11-2002 02:18 AM
Re: ping RETURN codes
I agree with Stefan. Have a conditional statement to set the return code, like this:
# if ping 1.2.3.4 -n 3 | grep '100%' >/dev/null 2>&1 ; then exit 1; else exit 0 ; fi
# echo $?
1
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2002 02:31 AM
тАО07-11-2002 02:31 AM
Re: ping RETURN codes
pereal - /home/trsh # /etc/ping bobby -n 1
/etc/ping: unknown host bobby
pereal - /home/trsh # echo $?
1
Anyway, thanks for the info!
I'll incorporate that!
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2002 03:42 AM
тАО07-11-2002 03:42 AM
Re: ping RETURN codes
If for a particular command, i.e. ping(1M) in this case, "RETURN VALUE" is not *documented*, then don't assume it is set (to some meaningful, reliable, etc. value). I.e. the right approach is somthingike Steven has suggested.
If you want to blame someone, then blame the AUTHOR! :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2002 04:39 AM
тАО07-11-2002 04:39 AM
Re: ping RETURN codes
The fact that the remote end failed to respond correctly is problematic in terms of a single return code. The IP address may truly be unresponsive (the main reason we use ping) but it might work a few times and fail a few times, or (due to a duplicate IP) get a multiple returns for the same ping attempt, or there might be an excessive delay in getting the ping back.
So as mentioned, ping must be parsed in order to determine exactly what is happening.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2002 05:56 AM
тАО07-11-2002 05:56 AM
Re: ping RETURN codes
Here's one method that will give you a reliable
exit status (0 = good; non-zero bad like a good little program): This one pings and time outs in 5 seconds if no response.
ping.pl -t 5 remote_host
STAT=$?
if [ ${STAT} -eq 0 ]
then
echo "Good"
fi
Invoke it as ping.pl -u for full usage. Note, if you are using this script on a Windows box, you should comment out the alarm() function. It's not supported on Windows.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2002 08:23 AM
тАО07-11-2002 08:23 AM
Re: ping RETURN codes
How about this way?
for system in `cat $WORK_DIR/criping.source`
do
if /etc/ping $system 64 1 > /dev/null
then
RET2="`echo $system` `/etc/ping $system 64 1 | grep bytes | awk {'print $6'}`"
echo $RET2 | grep -v time >> $WORK_DIR/criping.result
fi
done
Then proceed by [ -s $WORK_DIR/criping.result ].
You may want to run a loop for two runs, as ping may not sometimes succeed the first time.
Hope this helps,
Thanks
Anu Mathew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2002 02:13 AM
тАО07-12-2002 02:13 AM
Re: ping RETURN codes
Use ping from 10.20 - that works fine (we got this info from HP)
We got the binary from them because we only have 11.0
We wait since 1 year for the patch for 11.0