Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Ubuntu User (http://www.linux-archive.org/ubuntu-user/)
-   -   internet connection tester script (http://www.linux-archive.org/ubuntu-user/347891-internet-connection-tester-script.html)

Rameez Thonnakkal 03-27-2010 02:39 PM

internet connection tester script
 
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





Modified script, tested..

http://pastebin.com/HwCujzWj

--rameez

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

Jozsef Vadkan 03-28-2010 01:21 PM

internet connection tester script
 
wow...thanks:D

2010. 03. 27, szombat keltezéssel 21.09-kor Rameez Thonnakkal ezt írta:
>
>
>
> 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
>
>
> Modified script, tested..
>
> http://pastebin.com/HwCujzWj
>
> --rameez


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

kellyremo 01-28-2011 10:28 AM

internet connection tester script
 
http://pastebin.com/raw.php?i=rykHdvBh

bix.hu and www.yahoo.com are "pingable" test sites.
127.0.0.1 could not be pinged [firewall drops all icmp]

i have a "oneliner" that echoes if theres "internet connection or no".
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
internet connection ok
$ ping -W 1 -c 2 127.0.0.1 >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 127.0.0.1 >& /dev/null && ping -W 1 -c 2 127.0.0.1 >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 127.0.0.1 >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
internet connection ok
$

Ok!

But: if i want the "oneliner" to only go along when theres internet connection:
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 127.0.0.1 >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 127.0.0.1 >& /dev/null && ping -W 1 -c 1 127.0.0.1 >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 127.0.0.1 >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$

It just doesn't work.

Goal: if theres no internet connection, then the oneliner must loop until there is internet connection. if theres internet connection the oneliner ends.

what am i missing?
--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

kellyremo 01-28-2011 10:28 AM

internet connection tester script
 
http://pastebin.com/raw.php?i=rykHdvBh

bix.hu and www.yahoo.com are "pingable" test sites.
127.0.0.1 could not be pinged [firewall drops all icmp]

i have a "oneliner" that echoes if theres "internet connection or no".
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
internet connection ok
$ ping -W 1 -c 2 127.0.0.1 >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 127.0.0.1 >& /dev/null && ping -W 1 -c 2 127.0.0.1 >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 127.0.0.1 >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
internet connection ok
$

Ok!

But: if i want the "oneliner" to only go along when theres internet connection:
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 127.0.0.1 >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 127.0.0.1 >& /dev/null && ping -W 1 -c 1 127.0.0.1 >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 127.0.0.1 >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$

It just doesn't work.

Goal: if theres no internet connection, then the oneliner must loop until there is internet connection. if theres internet connection the oneliner ends.

what am i missing?__________________________________________ _____
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

kellyremo 01-28-2011 10:28 AM

internet connection tester script
 
http://pastebin.com/raw.php?i=rykHdvBh

bix.hu and www.yahoo.com are "pingable" test sites.
127.0.0.1 could not be pinged [firewall drops all icmp]

i have a "oneliner" that echoes if theres "internet connection or no".
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
internet connection ok
$ ping -W 1 -c 2 127.0.0.1 >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 127.0.0.1 >& /dev/null && ping -W 1 -c 2 127.0.0.1 >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 127.0.0.1 >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
internet connection ok
$

Ok!

But: if i want the "oneliner" to only go along when theres internet connection:
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 127.0.0.1 >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 127.0.0.1 >& /dev/null && ping -W 1 -c 1 127.0.0.1 >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 127.0.0.1 >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$

It just doesn't work.

Goal: if theres no internet connection, then the oneliner must loop until there is internet connection. if theres internet connection the oneliner ends.

what am i missing?
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

kellyremo 01-28-2011 10:28 AM

internet connection tester script
 
http://pastebin.com/raw.php?i=rykHdvBh

bix.hu and www.yahoo.com are "pingable" test sites.
127.0.0.1 could not be pinged [firewall drops all icmp]

i have a "oneliner" that echoes if theres "internet connection or no".
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
internet connection ok
$ ping -W 1 -c 2 127.0.0.1 >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 127.0.0.1 >& /dev/null && ping -W 1 -c 2 127.0.0.1 >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 127.0.0.1 >& /dev/null && echo "internet connection ok" || echo "no internet connection"
no internet connection
$ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 www.yahoo.com >& /dev/null && echo "internet connection ok" || echo "no internet connection"
internet connection ok
$

Ok!

But: if i want the "oneliner" to only go along when theres internet connection:
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 127.0.0.1 >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 127.0.0.1 >& /dev/null && ping -W 1 -c 1 127.0.0.1 >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 127.0.0.1 >& /dev/null && TORF=false || TORF=true; done
$ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
$

It just doesn't work.

Goal: if theres no internet connection, then the oneliner must loop until there is internet connection. if theres internet connection the oneliner ends.

what am i missing?

"Bryn M. Reeves" 01-28-2011 10:56 AM

internet connection tester script
 
On 01/28/2011 11:28 AM, kellyremo wrote:
>
> http://pastebin.com/raw.php?i=rykHdvBh
>
> bix.hu and www.yahoo.com are "pingable" test sites.
> 127.0.0.1 could not be pinged [firewall drops all icmp]
>
> i have a "oneliner" that echoes if theres "internet connection or no".
> $ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 www.yahoo.com >&
> /dev/null && echo "internet connection ok" || echo "no internet connection"
> internet connection ok
> $ ping -W 1 -c 2 127.0.0.1 >& /dev/null && ping -W 1 -c 2 www.yahoo.com >&
> /dev/null && echo "internet connection ok" || echo "no internet connection"
> no internet connection
> $ ping -W 1 -c 2 127.0.0.1 >& /dev/null && ping -W 1 -c 2 127.0.0.1 >& /dev/null
> && echo "internet connection ok" || echo "no internet connection"
> no internet connection
> $ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 127.0.0.1 >& /dev/null &&
> echo "internet connection ok" || echo "no internet connection"
> no internet connection
> $ ping -W 1 -c 2 bix.hu >& /dev/null && ping -W 1 -c 2 www.yahoo.com >&
> /dev/null && echo "internet connection ok" || echo "no internet connection"
> internet connection ok
> $
>
> Ok!
>
> But: if i want the "oneliner" to only go along when theres internet connection:
> $ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1
> www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
> $ while $TORF; do ping -W 1 -c 1 127.0.0.1 >& /dev/null && ping -W 1 -c 1
> www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
> $ while $TORF; do ping -W 1 -c 1 127.0.0.1 >& /dev/null && ping -W 1 -c 1
> 127.0.0.1 >& /dev/null && TORF=false || TORF=true; done
> $ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 127.0.0.1
> >& /dev/null && TORF=false || TORF=true; done
> $ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1
> www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
> $
>
> It just doesn't work.
>
> Goal: if theres no internet connection, then the oneliner must loop until there
> is internet connection. if theres internet connection the oneliner ends.
>
> what am i missing?
>

Instead of using a variable (that has funky scoping in shell) just make the &&
compound command the loop condition and place it in a subshell:

while (! ping -W 1 -c 1 bix.hu && ! ping -W 1 -c 1 www.yahoo.com )&>/dev/null;
do /bin/true ; done

Or you can write the same as:

while (! (ping -W 1 -c 1 bix.hu && ping -W 1 -c 1 www.yahoo.com))&>/dev/null; do
/bin/true ; done

It's probably not the best way to do it though - this little shell loop eats up
fair bit of CPU time.

Just putting a "sleep 1" instead of /bin/true makes the load barely noticable
but if you're on a system that's using Network Manager then you could also look
at the information provided by the nmcli tool to see if it would meet your
requirements.

Regards,
Bryn.
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

Philippe Naudin 01-28-2011 11:01 AM

internet connection tester script
 
Le ven 28 jan 2011 03:28:22 CET, kellyremo a écrit:

> [ ... ]
> $ while $TORF; do ping -W 1 -c 1 bix.hu >& /dev/null && ping -W 1 -c 1 www.yahoo.com >& /dev/null && TORF=false || TORF=true; done
> $
>
> It just doesn't work.
>
> Goal: if theres no internet connection, then the oneliner must loop until there is internet connection. if theres internet connection the oneliner ends.
>
> what am i missing?

try :
until ping -W 1 -c 1 bix.hu || ping -W 1 -c 1 www.yahoo.com ; do
sleep 5
done >& /dev/null

Note that ping -W 1 is crazy.

--
Philippe
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

Nils Kassube 01-28-2011 11:11 AM

internet connection tester script
 
kellyremo wrote:
> http://pastebin.com/raw.php?i=rykHdvBh

Hmm, why do you use pastebin if you post the code here anyway?

> bix.hu and www.yahoo.com are "pingable" test sites.
> 127.0.0.1 could not be pinged [firewall drops all icmp]

If your firewall drops all ICMP you can't ping any site. However, if you
mean that your firewall blocks only ICMP for localhost, you should
reconsider your firewall rules.


Nils

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

John R Pierce 01-28-2011 11:19 AM

internet connection tester script
 
On 01/28/11 3:28 AM, kellyremo wrote:
> bix.hu and www.yahoo.com are "pingable" test sites.
> 127.0.0.1 could not be pinged [firewall drops all icmp]


what sort of firewall drops packets on localhost ?!?

yahoo.com is probably a poor choice of targets, as its a widely
distributed group of servers, and you likely will be pinging different
servers at different times, maybe even in different parts of the world.
I would instead suggest using a target at your ISP or backbone provider.

btw, dropping 'all icmp' is bad practice. Internet Control Message
Protocol is used for a number of things, including informing
applications when a host or port is not accessible. if you drop this,
you instead hang for minutes waiting for a response instead of quickly
getting back a 'target {host|port} not reachable' error.

anyways, if you drop all ICMP, you won't get any pings from anywheres.


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


All times are GMT. The time now is 12:17 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.