Operating System - HP-UX
1835910 Members
2691 Online
110086 Solutions
New Discussion

Re: Speeding up result of ping test... Already use the -n option

 
SOLVED
Go to solution
Jack C. Mahaffey
Super Advisor

Speeding up result of ping test... Already use the -n option

Is there anyway to speed up the output returned from pinging hosts? e.g. ping -n 3

I have a script that pings a series of hosts to verify that they are operational. I cut the number of ping attempts to three and the script sleeps a couple of seconds between the pings. Any ideas to speed up the script?

jack...

8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: Speeding up result of ping test... Already use the -n option

Hi Jack:

Remove the sleep :-))

'ping' is going to operate about as fast as the network echo will traffic. Without seeing your script it's difficult to suggest optimizations.

Regards!

...JRF...
Jack C. Mahaffey
Super Advisor

Re: Speeding up result of ping test... Already use the -n option

Not much to the script...
for z in $HOSTLIST
do
ping $z -n 3
sleep 2
done


I had the sleep in there to have a short delay. Had a feeling if ping ran right after the previous attempt, it might be to soon.

jack...


James R. Ferguson
Acclaimed Contributor

Re: Speeding up result of ping test... Already use the -n option

Hi Jack:

A senseless, repetious use of 'ping' might degrade a network, but for your purposes, drop the 'sleep()' and let your script work through the list. The use of 3-pings per device is quite conservative, but quite sufficient, in my opinion.

Regards!

...JRF...
Arunvijai_4
Honored Contributor

Re: Speeding up result of ping test... Already use the -n option

Hi Jack,

The ping command sends ICMP Echo Request(ECHO_REQUEST) packets to the host once per second. I think you can't speed them more.


-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Paul Sperry
Honored Contributor

Re: Speeding up result of ping test... Already use the -n option

Jack,

We use the folowing perl script to page our servers. If one is down I get a page. It also keeps a log.

#!/usr/bin/perl


if ($ARGV[0] eq "")
{
die "Usage: pingcheck \n";
}

$BINDIR = "/bin";
$FILE = $ARGV[0];
$WORKDIR = "/usr/local/etc";
$LOGDIR = "/var/log";
$LOGFILE = "ping.log";

open (SERVERS,"$WORKDIR/$FILE") || die "Cannot open $WORKDIR/$FILE: $!\n";

while ()
{
chomp;
$result = `$BINDIR/ping -c 5 $_`;
if ($result =~ "100% packet loss")
{
system("$BINDIR/echo \"Cannot ping $_\" `date` | $BINDIR/mail -s \"Cannot ping $_\" techpgr\@ourdomain.com");
system("$BINDIR/echo \"CANNOT ping $_\" `date` >> $LOGDIR/$LOGFILE");
# system("$BINDIR/echo \"CANNOT ping $_\" `date`");
}
else
{
system("$BINDIR/echo \"ping ok $_\" `date` >> $LOGDIR/$LOGFILE");
# system("$BINDIR/echo \"ping ok $_\" `date`");
}
}

close SERVERS;
Bill Thorsteinson
Honored Contributor
Solution

Re: Speeding up result of ping test... Already use the -n option

Try reducing the timout with the -m option,
this will return missed echos faster.
Reduce -n to 1 or 2. It is rare for echos
not to be replied to.
Drop the sleep.

Try something like:

ping host -n 1 -m 2

Jack C. Mahaffey
Super Advisor

Re: Speeding up result of ping test... Already use the -n option

my version of ping does not support the -m or -c options.

Dropping the sleep and setting -n value to 2.

Thanks all....

Always learn things from these forums... :)

rick jones
Honored Contributor

Re: Speeding up result of ping test... Already use the -n option

If the other systems happen to be HP-UX, or happen to support linkloop (http://freshmeat.net/projects/linkloop/) you could use linkloop instead, which if the system is there will return quite quickly.
there is no rest for the wicked yet the virtuous have no pillows