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

Re: whats wrong with my internet connection checker script?



2010/12/26 S Mathias <smathias1972@yahoo.com>:
> $ true && true || echo hi
> $ true && false || echo hi
> hi
> $ false && true || echo hi
> hi
> $ false && false || echo hi
> hi
Hi I was  trying  with this logic of the internet connection checker script.
If $ true && true || echo hi   <<< All right

if  $ true && false || echo hi
or $ false && true || echo hi
or $ false && false || echo hi  <<<< the connection is broken

This my implementation of the checker script:
ping -W 1 -c 4  google.com && ping -W 1 -c 4  yahoo.com || echo "The
connection is broken"

This when the Internet connection is broken:
ceduard0@madmax:~/workspace/ngl/Debug$ ping -W 1 -c 4  google.com &&
ping -W 1 -c 4  yahoo.com || echo "broken"
ping: unknown host google.com
broken
ceduard0@madmax:~/workspace/ngl/Debug$ ping -W 1 -c 4  google.com &&
ping -W 1 -c 4  yahoo.com || echo "broken"
ping: unknown host google.com
broken
ceduard0@madmax:~/workspace/ngl/Debug$ ping -W 1 -c 4  google.com &&
ping -W 1 -c 4  yahoo.com || echo "broken"
ping: unknown host google.com
broken
ceduard0@madmax:~/workspace/ngl/Debug$ ping -W 1 -c 4  google.com &&
ping -W 1 -c 4  yahoo.com || echo "broken"
ping: unknown host google.com
broken

This when the Internet connection are right
ceduard0@madmax:~/workspace/ngl/Debug$ ping -W 1 -c 4  google.com &&
ping -W 1 -c 4  yahoo.com || echo "broken"
PING google.com (74.125.65.104) 56(84) bytes of data.
64 bytes from gx-in-f104.1e100.net (74.125.65.104): icmp_req=1 ttl=55
time=91.0 ms
64 bytes from gx-in-f104.1e100.net (74.125.65.104): icmp_req=2 ttl=55
time=81.5 ms
64 bytes from gx-in-f104.1e100.net (74.125.65.104): icmp_req=3 ttl=55
time=85.8 ms
64 bytes from gx-in-f104.1e100.net (74.125.65.104): icmp_req=4 ttl=55
time=80.0 ms

--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 80.048/84.627/91.077/4.303 ms
PING yahoo.com (72.30.2.43) 56(84) bytes of data.
64 bytes from ir1.fp.vip.sk1.yahoo.com (72.30.2.43): icmp_req=1 ttl=53
time=151 ms
64 bytes from ir1.fp.vip.sk1.yahoo.com (72.30.2.43): icmp_req=2 ttl=53
time=148 ms
64 bytes from ir1.fp.vip.sk1.yahoo.com (72.30.2.43): icmp_req=3 ttl=53
time=145 ms
64 bytes from ir1.fp.vip.sk1.yahoo.com (72.30.2.43): icmp_req=4 ttl=53
time=140 ms

--- yahoo.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3001ms
rtt min/avg/max/mdev = 140.337/146.438/151.636/4.140 ms


> $ ping -W 1 -c 4 google.com >& /dev/null | grep -q "100% packet loss" && ping -W 1 -c 4 www.yahoo.com >& /dev/null | grep -q "100% packet loss" || echo "no internet connection"
> no internet connection
> $
> ping -W 1 -c 4 google.com >& /dev/null | grep "100% packet loss"
> $
> ping -W 1 -c 4 www.yahoo.com >& /dev/null | grep "100% packet loss"
> $
>
>
>
> ...both sides "false", because they have no output, because google.com and www.yahoo.com is reachable.
> how come it writes "no internet connection"? [at the longest line]
> i just want a "oneliner" that checks if theres "internet connection" or no. :\
>
> where did i screw up? 8)
>
>
>
>
>
> --
> To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
> Archive: [🔎] 471466.28989.qm@web121403.mail.ne1.yahoo.com">http://lists.debian.org/[🔎] 471466.28989.qm@web121403.mail.ne1.yahoo.com
>
>



-- 
ceduard0


Reply to: