[ltp] OT: how to time a ping command?
Eben King
linux-thinkpad@linux-thinkpad.org
Sun, 19 Sep 2004 20:03:27 -0400 (EDT)
On Mon, 20 Sep 2004, André Wyrwa wrote:
> can anyone tell me how i can time a ping command? I can do a -c 1 -i 0
> to time one resulting positive, but if the server is not found the
> command never returns, so it seems i need to find a way to terminate it
> from outside after some time. But how (killall is to be avoided)?
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.
I think that'll do what you want.
I implemented such a test once. As either I did not know about that or it
didn't exist at the time, what I did was something like
ping -c 1 somehost > ping_output &
sleep 1
kill %1
grep -q 'some_expr' ping_output && ip_up
although I'm sure there were some loops and a wait in there.
--
-eben ebQenW1@EtaRmpTabYayU.rIr.OcoPm home.tampabay.rr.com/hactar
Hanlon's Razor: "Never attribute to malice that which can be
adequately explained by stupidity." Derived from Robert Heinlein