From owner-freebsd-questions@FreeBSD.ORG Sat Mar 27 12:46:51 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 602D1106566C for ; Sat, 27 Mar 2010 12:46:51 +0000 (UTC) (envelope-from faust64@gmail.com) Received: from mail-bw0-f216.google.com (mail-bw0-f216.google.com [209.85.218.216]) by mx1.freebsd.org (Postfix) with ESMTP id D42F48FC08 for ; Sat, 27 Mar 2010 12:46:50 +0000 (UTC) Received: by bwz8 with SMTP id 8so3653887bwz.3 for ; Sat, 27 Mar 2010 05:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:received:message-id:subject:to:cc:content-type; bh=RiZr3icC5dmsQEIxWxkN28OR/0LbQdgIwEGkY7sRrI8=; b=wItTnAXe3aDWsvvAUuvEBrIwV4DwOq1NpNUnMbee7+YDP0OYdwiujSkhtckGUVAPtT tdC7/7Mviit9E7MsiE7H4zEHC3BVJwGNf6KWtoZ5lhboTKLa7SZlza7SMYXwaiwzHVhH PxPVny5ayIeRgxlnNZkyeO9Xx9t/piDd+0f5E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=NcrCqSNDT12LFfFgiWu4UteqCq+0hi4xicMDzIVGoMqBf5Y7dB9TkExa0xsZQq+ZkN ga60XYa79fEUpadY6eucVAjWP/b+ONX0YiyeqE/Ih66ASLbopUgaOJDqiFJLGBhr09z1 pcjE7cNf2HeO0m/mNbnfeyQpnOVPjY3+8M9q0= MIME-Version: 1.0 Received: by 10.204.61.5 with HTTP; Sat, 27 Mar 2010 05:46:29 -0700 (PDT) In-Reply-To: <20100327132214.c414f2d2.freebsd@edvax.de> References: <1269691634.12702.11.camel@debian> <20100327132214.c414f2d2.freebsd@edvax.de> From: =?ISO-8859-1?Q?Samuel_Mart=EDn_Moro?= Date: Sat, 27 Mar 2010 13:46:29 +0100 Received: by 10.204.9.134 with SMTP id l6mr3425455bkl.83.1269694009202; Sat, 27 Mar 2010 05:46:49 -0700 (PDT) Message-ID: To: Polytropon Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Jozsef Vadkan , FreeBSD Mailing list Subject: Re: "internet connection tester script" X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Mar 2010 12:46:51 -0000 I prefer to use `host' command ping take time to run, especially when it do not respond... here's my script root@omega ~ : cat /usr/local/bin/check_connectivity 13:43 #!/bin/sh # checks local and internet connectivity # faust - 2010/02/17 host google.com >/dev/null if [ $? -eq 0 ]; then net=3D1 echo "Internet connection is UP" else net=3D0 echo "Internet connection is DOWN" fi host alpha.faust-network >/dev/null if [ $? -eq 0 ]; then local=3D1 echo "Local network is UP" else local=3D0 echo "local network is DOWN" fi case `expr $local '*' 2 + $net` in 0) exit 2 ;; # big nothing 1) exit 42 ;; # just internet (uhu?) 2) exit 1 ;; # just local 3) exit 0 ;; # all right! *) exit 43 ;; # divided by zero? esac Samuel Mart=EDn Moro {EPITECH.} tek4 CamTrace S.A.S On Sat, Mar 27, 2010 at 1:22 PM, Polytropon wrote: > On Sat, 27 Mar 2010 13:07:14 +0100, Jozsef Vadkan > wrote: > > Why doesn't my "internet-connection" script work? > > > > When I plug the ethcable out, it just waits...and waits...and waits... > > It doesn't even work correctly: Now as I definitely have > Internet connection, it prints "NO INTERNET CONNECTION". > > Allow me a comment: > > #!/bin/bash > > This is Linux. It is not portable. FreeBSD is NOT Linux. > > In FreeBSD, the standard scripting shell is the Bourne > shell /bin/sh. Unless you don't require things that are > specific to bash, use the correct shebang for shm which is > > #!/bin/sh > > If you intendedly want to use bash, specify it correctly: > > #!/usr/local/bin/bash > > The bash is an additional package for FreeBSD, it does not > belong to the OS itself. It needs to be installed. Of > course, there's a way to make bash available as /bin/bash > statically linked, but with all thoughts to interoperability, > I wouldn't rely on this. > > Let me bring the script into a more easily readable form > and allow me to say something about it: > > #!/bin/sh > > function internet_connection_ok > { > echo "Testing internet connection....please wait..." > if ping -W 1 -c 4 bix.hu | grep -q "4 received"; then > if ping -W 1 -c 4 www.yahoo.com | grep -q "4 received"; > then > echo "NET is OK" > else > echo "NO INTERNET CONNECTION" > exit 1 > fi > else > echo "NO INTERNET CONNECTION" > exit 1 > fi > } > > internet_connection_ok > > Basically, you're relying on a 100 % correct reception of > pings from two specified host to see if Internet is up and > running. In case of package loss, even with running Internet > (e. g. 4 sent, 3 received), the script would say that there's > no Internet connection, which is false. Additionally, you're > giving only 1 ms for reply, which may not be enough for a > slow (but stable) connection. Finally, you're relying on > DNS to get the IPs to ping for bix.hu and www.yahoo.com. > I'm not sure if this resolve time is important here, too. > > > > > -- > Polytropon > Magdeburg, Germany > Happy FreeBSD user since 4.0 > Andra moi ennepe, Mousa, ... > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to " > freebsd-questions-unsubscribe@freebsd.org" >