[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: internet connection tester script



On 28.01.2011 12:28, 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?


until ping -c 1 host &>/dev/null; do echo "offline"; sleep 1; done
while ! ping -c 1 host &>/dev/null; do echo "offline"; sleep 1; done

no need to set the TORF variable. use the exit status of the command.

The while command continuously executes the do list as long as the last command in list returns an exit status of zero.
For until it's the other way round.

Best regards

Mart


Reply to: