bash: check for network

Byron Clark byron at
Fri Apr 15 11:35:34 MDT 2005

On Fri, Apr 15, 2005 at 11:17:12AM -0600, Justin Gedge wrote:
> This is where you get back to the whole mess of using grep.  You don't 
> want to check wether ping ran or not-- you want to check what the 
> results of ping were.  Pipe the results of ping through grep-- and 
> filter on " 0%" or  " 100%".  Also-- putting the -w for timout is good 
> too-- otherwise ping may sit there for quite a while.  I figure-- on a 
> good network [locally] if your ping is over 1s there are other problems 
> at large.

Using grep to see if ping succeeded or not is "the hard way."  ping has
an exit code of 0 if there are no errors and there is a response; the
exit code is 1 or 2 otherwise.  I know someone already showed the easy
way, but just to reiterate:

if ping -c 1 -w 1 -q &>/dev/null; then
    echo " is up"
    echo " is down"

Byron Clark                     |
byron at       | 
GnuPG Fingerprint: 0365 6979 6C3E BC0C 56C0 FB7F 12B3 75DD 042B EA68

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : 

More information about the PLUG mailing list