From owner-freebsd-questions@FreeBSD.ORG Sat Mar 27 12:22:16 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 B3A81106564A for ; Sat, 27 Mar 2010 12:22:16 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) by mx1.freebsd.org (Postfix) with ESMTP id 756D98FC0C for ; Sat, 27 Mar 2010 12:22:16 +0000 (UTC) Received: from r55.edvax.de (port-92-195-100-7.dynamic.qsc.de [92.195.100.7]) by mx01.qsc.de (Postfix) with ESMTP id 10A293D8DB; Sat, 27 Mar 2010 13:22:14 +0100 (CET) Received: from r55.edvax.de (localhost [127.0.0.1]) by r55.edvax.de (8.14.2/8.14.2) with SMTP id o2RCMEHM001772; Sat, 27 Mar 2010 13:22:14 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Sat, 27 Mar 2010 13:22:14 +0100 From: Polytropon To: Jozsef Vadkan Message-Id: <20100327132214.c414f2d2.freebsd@edvax.de> In-Reply-To: <1269691634.12702.11.camel@debian> References: <1269691634.12702.11.camel@debian> Organization: EDVAX X-Mailer: Sylpheed 2.4.7 (GTK+ 2.12.1; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: FreeBSD Mailing list Subject: Re: "internet connection tester script" X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Mar 2010 12:22:16 -0000 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, ...