[ltp] OT: how to time a ping command?
Eben King
linux-thinkpad@linux-thinkpad.org
Sun, 19 Sep 2004 20:49:51 -0400 (EDT)
On Mon, 20 Sep 2004, André Wyrwa wrote:
> Hei,
>
> > from ping.1:
> >
> > -w deadline
> > Specify a timeout, in seconds, before ping exits regardless of
> > how many packets have been sent or received. In this case ping
> > does not stop after count packet are sent, it waits either for
> > deadline expire or until count probes are answered or for some
> > error notification from network.
>
> Funny, that's exactly what i'm looking for, but my ping.1 doesn't
> include this and neither does my ping.
> Can you post your --version output please? Mine is from GNU inetutils
> 1.4.2 .
Doesn't have that option, but it does have -V:
[eben@pc eben]$ ping -V
ping utility, iputils-ss020124
> > ping -c 1 somehost > ping_output &
> > sleep 1
> > kill %1
> > grep -q 'some_expr' ping_output && ip_up
>
> Ahh...didn't know about the %1 thing, thx. I'll take that as a fallback
> if i can't get my ping to support the -w option. ;-)
I did something much faster (which I can't recall verbatim). It would do
something like
ping -c 1 somehost > /dev/null &
ping_pid=$!
{ sleep 1 ; kill $ping_pid ; } &
sleep_pid=$!
wait $ping_pid
kill -0 $sleep_pid && # internet connection is up
kill $sleep_pid
(At least that's how I THINK I did it.) Net effect was that you would
only wait for the timeout if the ping wasn't returned. Normally there
would just be a ping then life would go on.
--
-eben ebQenW1@EtaRmpTabYayU.rIr.OcoPm home.tampabay.rr.com/hactar
An idea that is not dangerous is unworthy of
being called an idea at all. -Oscar Wilde