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? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20110128/f4aa185a/attachment-0002.html>
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
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.