- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ping exitcode and timeout on HP-UX 11.00
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
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
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
09-17-2001 12:49 AM
09-17-2001 12:49 AM
When I ping a non-existing host, I have 2 problems.
1. I can't set a timeout (default ~10 sec.)
2. The exitcode is 0
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2001 01:25 AM
09-17-2001 01:25 AM
Re: ping exitcode and timeout on HP-UX 11.00
www.fping.com
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2001 01:33 AM
09-17-2001 01:33 AM
Re: ping exitcode and timeout on HP-UX 11.00
result=`ping $HOST -n 1 | grep '100% packet loss'`
if [ ! -z "$result" ]
then
echo ping failed
else
echo ping OK
fi
For problem 1, if you can determine the hardware station address (Station Address in lanscan(1M)) of the host, you can perhaps use the linkloop(1M) command (which has a timeout parameter) instead of ping. Note however that chosing a short timeout can lead to false negatives, i.e. host is up, but just it or the network are 'slow'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2001 01:59 AM
09-17-2001 01:59 AM
Re: ping exitcode and timeout on HP-UX 11.00
Frank: I use 'grep "packets from"'.
I can't use HW-adr. when running through a router ....
Thanks for the answers both af you.
(Why did HP remove -m, it worked in 10.20)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2001 02:09 AM
09-17-2001 02:09 AM
Re: ping exitcode and timeout on HP-UX 11.00
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2001 02:55 AM
09-17-2001 02:55 AM
Re: ping exitcode and timeout on HP-UX 11.00
#!/bin/sh
if test $# -le 2
then
HOST=$1
TIMEOUT=2
test $# -eq 2 && TIMEOUT=$2
ping $HOST -n 1 >/dev/null 2>&1 &
sleep $TIMEOUT
PID=`ps -ef | grep "ping $HOST" | grep -v grep | awk '{ print $2 }'` >/dev/null 2>&1
if kill $PID >/dev/null 2>&1
then
echo down # Do stuff here
else
echo up # Do stuff here
fi
else
echo "Usage: $0 HOST [TIMEOUT]" >&2
fi
Problem:
Now for every host, the timeout is 2 sec.
I have to test 100 hosts, where 10 is down.
Normal ping of host is around 1/2 sec. if its up. 10 sec. if its down.
Whithout this script, the total time is:
90 * 1/2 + 10 * 10 = 145 sec.
Whith the script total time is:
100 * 2 = 200 sec.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2001 04:03 AM
09-17-2001 04:03 AM
Re: ping exitcode and timeout on HP-UX 11.00
here my solution for 100 sec's:
for host in hostname ....
do
(ping $host -n 1) >/dev/null 2>&1 &
sleep 1
kill $! >/dev/null 2>&1
if [ $? = 0 ]
then
echo "Host $host is down"
else
echo "Host $host is up"
fi
done
It check if the ping process lives after one second (if the process is gone, kill returns a non zero status)
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2001 04:18 AM
09-17-2001 04:18 AM
SolutionOkay did some scripting...see if this helps any:
#!/bin/sh
if test $# -le 2
then
HOST=$1
TIMEOUT=5
test $# -eq 2 && TIMEOUT=$2
(ping $HOST -n 1 >/dev/null 2>&1)&
PID=$!
count=1
while [[ $count -lt $TIMEOUT ]]
do
ps -ef |grep "ping $HOST" |grep -v grep >/dev/null 2>&1
if [[ $? -ne 0 ]]
then
break
fi
let count=count+1
sleep 1
done
if kill $PID >/dev/null 2>&1
then
echo down # Do stuff here
else
echo up # Do stuff here
fi
else
echo "Usage: $0 HOST [TIMEOUT]" >&2
fi
Also, to speed things up, you could probably kick off several ping at one time and monitor them simultaneously...although I'm not sure what kind of a load pinging 100 machines would put on the machine.
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2001 04:39 AM
09-17-2001 04:39 AM
Re: ping exitcode and timeout on HP-UX 11.00
I will use some variant of the above solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2001 06:31 AM
09-17-2001 06:31 AM
Re: ping exitcode and timeout on HP-UX 11.00
Using:
ps -ef | grep
is not a reliable way of locating a process at all. grep does not discriminate between ping and helping and pinger...they all return a value, which is not desired, especially if your script kills the wrong program.
Instead, use ps -C which allows you to specify the exact command name (ie, ping) and ps will find it for you. It does not use grep but instead goes through the process table for an exact match. In order to use ps -C (or ps -H and others), you'll need to temporarily set UNIX95 as a variable -- which cause XPG4 behavior. Compare these two commands:
ps -ef | grep sh
UNIX95= ps -fC sh
And sinc the script needs to kill a specific process, you probably should check for more than one copy of ping running.
Or an even better way is to bypass grep'ing for ping and just ask the shell what the PID was for the background process:
ping 12.34.56.78 &
PINGPID=$!
Now you know exactly whivh process to test or kill if needed.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2001 01:14 AM
09-19-2001 01:14 AM
Re: ping exitcode and timeout on HP-UX 11.00
HP is working on a patch for HP-UX 11.00.
Exit status:
On 10.20 the exit-status is correct if patch: PHNE_19566/PACHRDME/English is installed.
This patch will (afaik) be "ported" to 11.00.
Timeout:
On 10.20 there is a -m option
ping -m 1 host -n 1
On 11.00 there is a (unsupported) -W option
ping -W 1 host -n 1
-m/-W is timeout in sec., and is only available with -n.