whats wrong with my internet connection checker script?

Oliver Grawert ogra at ubuntu.com
Sun Dec 26 22:49:20 UTC 2010


hi,
Am Sun, 26 Dec 2010 14:30:32 -0800 (PST)
schrieb S Mathias <smathias1972 at yahoo.com>:
> ping -W 1 -c 4 google.com >& /dev/null | grep "100% packet loss"
> $
> ping -W 1 -c 4 www.yahoo.com >& /dev/null | grep "100% packet loss"
> $
...
> ...both sides "false", because they have no output, because
> google.com and www.yahoo.com is reachable. how come it writes "no
> internet connection"? [at the longest line] i just want a "oneliner"
> that checks if theres "internet connection" or no. :\
> 
> where did i screw up? 8)

you pipe all output to /dev/null, there is nothing left to grep for. so
the return value of the command (grep in this case) is always non zero,
just drop the grep so || only checks for the return values of the pings.

ciao
	oli




More information about the ubuntu-users mailing list