S Mathias wrote:
> perfect! thank you Oliver Grawert! :) made my day :) it's working! :
> 
> ping -W 1 -c 4 google.com >& /dev/null && ping -W 1 -c 4 www.yahoo.com >& 
> /dev/null || echo "no internet connection"

The ping documentation says:

       -c count
              Stop after sending count ECHO_REQUEST packets.  With
              deadline option, ping waits for count ECHO_REPLY
              packets, until the timeout expires.

       -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.

       [...]
       If ping does not receive any reply packets at all it will exit
       with code 1.  If a packet count and deadline are both specified,
       and fewer than count packets are received by the time the
       deadline has arrived, it will also exit with code 1.  On other
       error it exits with code 2.   Otherwise it exits with code
       0.  This makes it possible to use the exit code to see if a host
       is alive or not.

Therefore I think the correct way to use the return code of ping is to
specify both -c and -w options.  I don't think you need the -W option.

  $ ping -c 4 -w 4 google.com &> /dev/null && ping -c 4 -w 4 www.yahoo.com &> 
/dev/null || echo "no internet connection"

Bob

Attachment: signature.asc
Description: Digital signature

Reply via email to