On Wed, Feb 22, 2017 at 04:58:05PM +0000, Mark Rogers wrote:
On 22 February 2017 at 16:34, Simon Ransome simon@nosher.net wrote:
This does it in exactly one second, if that's any use:
ping -c1 n.n.n.n -w1
(just look for "100% packet loss" in the output).
ping also returns 0 on success and 1 on failure so checking $? is simpler than grepping the output.
You can get a sub-second test using fping: $ sudo apt-get install fping $ fping -c1 -t100 123.123.123.123
123.123.123.123 : xmt/rcv/%loss = 1/0/100% $ echo $? 1 $ fping -c1 -t100 8.8.8.8 8.8.8.8 : [0], 84 bytes, 9.79 ms (9.79 avg, 0% loss)
8.8.8.8 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 9.79/9.79/9.79 $ echo $? 0
fping also does nice things like pinging multiple hosts if needed.
I'm already using the return value in ssh config, as I showed before:-
#!/bin/bash # # # Test if specified host is ping'able # ! ping -c 1 $1 >>/dev/null 2>&1
The above (or the -w parameter for standard ping) is all I need to quicken the response enough. A one second delay is probably fine so I'll go with the -w1 with ping solution for the moment. If I get really impatient I can use fping as above! :-)
Thanks all.