On Fri, Dec 13, 2013 at 08:29:12AM +1100, Matthew Cengia wrote:
> >if $(ping -w 1 -c 1 -n 192.168.1.3 | grep -q "1 packets") ; then
>
> You shouldn't have the $() here at all. They're unnecessary and cause
> confusion.

you're right.  

actually, it's worse than that...in that context, they're broken because
command substitution - backticks or $(...)" - is only needed if you want
to examine the output of a command/pipeline or assign it to a variable
or similar. the code above won't work at all.

dunno what i was thinking....too sleepy to think straight last night.


> Further, don't bother checking ping's output with grep's return
> code. Check ping's return code instead:
> If ping -w1 -c1 -n 192.168.3.1 >/dev/null 2&>1; then 

true also.

i tend to use fping rather than ping to check if a host on the LAN is
responding:

fping is less verbose, has a handy -q (quiet) option to suppress output,
and you can specify the timeout in milliseconds (default 500ms) rather
than seconds.  50ms or even 10ms should be plenty of time for a host on
the local ethernet to respond (i'd expect under a millisecond or a few
ms at worst on a home 100baseT or gigabit network - of course that also
depends on how fast the pinged host is and how heavy its workload is
at the time).

if fping -t 50 -q 192.168.3.1 ; then ... ; fi
or
fping -t 50 -q 192.168.3.1 && ....


craig

-- 
craig sanders <[email protected]>
_______________________________________________
luv-main mailing list
[email protected]
http://lists.luv.asn.au/listinfo/luv-main

Reply via email to