- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Ping return code
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
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
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-04-2003 03:52 AM
тАО07-04-2003 03:52 AM
Ping return code
But the ping command does not return an error if no packets are received.
Any idea to get a return code ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2003 03:54 AM
тАО07-04-2003 03:54 AM
Re: Ping return code
Then grep the file for the keywords "packets transmitted" and "packets received", load up the numbers returned. If packets received is 0, ping was not succesfull!
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2003 04:00 AM
тАО07-04-2003 04:00 AM
Re: Ping return code
if [ $? = 0 ]
then
echo "$host: OK"
else
echo "$host: FAIL"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2003 04:27 AM
тАО07-04-2003 04:27 AM
Re: Ping return code
STAT1=$?
ping 2
STAT2=$?
if [[ $STAT1 != 0 ]]
then
echo alert1 | mailx -s "ALERT1 SUBJECT" you@yourdomain.com
fi
if [[ $STAT2 != 0 ]]
then
echo alert2 | mailx -s "ALERT1 SUBJECT" you@yourdomain.com
fi
Note:
'$?' saves success code of the last command completed, assign it to a variable like 'STAT1', run another command, save that success code in 'STAT2', etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2003 04:31 AM
тАО07-04-2003 04:31 AM
Re: Ping return code
In a shell script getting a return code is easy.
ping server.schmobagel.com #
return_code=$?
if [ $return_code ne 0 ] then
echo "ping server.schmobagel.com is down"
# email the administrator
# start a program to take over services
# blah blah blah
else
echo "all is well"
return 0
fi
Somewhere in my past posts there is a fully working copy of this script outline.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2003 05:56 AM
тАО07-04-2003 05:56 AM
Re: Ping return code
I observed the same problem as you. I had a function working on HP-UX 11.0 using the return code, but one day it stopped working (OS version, ping patch, ???).
Now I use the following function that seems OK at least on HP-UX11i v1:
test_server_access() {
#
# Test if the server given as parameter answers to ping
#
# Usage:
# test_server_access
#
# Return status:
# 0 = OK
# 1 = KO
#
# Test access to the server
RETURN=`ping $1 30 3 | tail -1 | awk '{print $1}'`
if [ ! $RETURN = "round-trip" ]; then
error_print "host $1 does not answer to ping" ; return 1
else
return 0
fi
}
Cheers,
Luc ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2003 07:31 AM
тАО07-04-2003 07:31 AM
Re: Ping return code
So you must always grep for the packet loss and for best performance, send several pings and grep for anything that is not 0% loss. It's also a good idea to look at the last line for unusual min/avg/max values (which might indicate a bad network).
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2003 07:41 AM
тАО07-04-2003 07:41 AM
Re: Ping return code
fping is a ping-like program which uses the Internet Control Message
Protocol (ICMP) echo request to determine if a host is up. fping
is different from ping in that you can specify any number of
hosts on the command line, or specify a file containing the
lists of hosts to ping. Instead of trying one host until it
timeouts or replies, fping will send out a ping packet and move
on to the next host in a round-robin fashion. If a host replies,
it is noted and removed from the list of hosts to check. If a
host does not respond within a certain time limit and/or retry
limit it will be considered unreachable.
You can obtain a copy from http://www.securityfocus.com/data/tools/fping-2.2b1.tar.gz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2003 10:01 AM
тАО07-05-2003 10:01 AM
Re: Ping return code
There is no return code from ping command,
you ccan write script that do this
ping
if ( $status == 0 ) then
print "connection"
else
print "no connection"
fi
You can write your program on C that will
open socket to the wanted hosts and
if succed/or not then return any code that you
want.
Caesar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2003 01:09 PM
тАО07-05-2003 01:09 PM