Re: internet connection tester script

2010-03-27 Thread Polytropon
On Sat, 27 Mar 2010 13:07:14 +0100, Jozsef Vadkan jozsi.avad...@gmail.com 
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 connectionplease 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-unsubscr...@freebsd.org


Re: internet connection tester script

2010-03-27 Thread Samuel Martín Moro
I prefer to use `host' command
ping take time to run, especially when it do not respond...

here's my script

r...@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=1
echo Internet connection is UP
else
net=0
echo Internet connection is DOWN
fi
host alpha.faust-network /dev/null
if [ $? -eq 0 ];
then
local=1
echo Local network is UP
else
local=0
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ín Moro
{EPITECH.} tek4
CamTrace S.A.S


On Sat, Mar 27, 2010 at 1:22 PM, Polytropon free...@edvax.de wrote:

 On Sat, 27 Mar 2010 13:07:14 +0100, Jozsef Vadkan jozsi.avad...@gmail.com
 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 connectionplease 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-unsubscr...@freebsd.org

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: internet connection tester script

2010-03-27 Thread Kevin Kinsey

Jozsef Vadkan wrote:

Why doesn't my internet-connection script work?

When I plug the ethcable out, it just waits...and waits...and waits...

The script: http://pastebin.com/AE9U1qdL


As someone has noted, you're waiting on ping to timeout a bunch
of times.  And really, I'm not sure why this script is needed.
In ~/.cshrc:

alias upping -t3 yahoo.com

 ... or something (your .bashrc equivalent, or .shrc, etc.)
should do the trick, with much less effort on all fronts.

HTH,

Kevin Kinsey
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: internet connection tester script

2010-03-27 Thread James
FWIW, here's what I use.  Requires net/fping.

#!/bin/sh

target=ip.address.of.next.hop.out

echo - Started at `date`

is_dead=0
while true; do
fping -q $target
fping_rc=$?

if [ $is_dead -eq 0 -a $fping_rc -gt 0 ]; then
echo ! Failure at `date`
is_dead=1
fi
if [ $is_dead -eq 1 -a $fping_rc -eq 0 ]; then
echo   Alive   at `date`
is_dead=0
fi

sleep 30
done

-- 
James.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org