linux - Ubuntu -If command seems do not provide else outcome -


i not understand why if script not working. when have internet connection in linux displays online phrase. when have no internet connection still displays online phrase instead offline.

#!/bin/bash # system_page - script monitor various connections , produce # system information in html file  ##### constants title="monitor information $hostname" right_now=$(date +"%x %r %z") time_stamp="updated on $right_now $user" # clear screen clear  echo -e "get http://google.com http/1.0\n\n" | nc google.com 80 >   /dev/null 2>&1    function net_info { if [ $? -eq 0 ]; echo "online" echo "<h2 style="background-color:#00ff00"><font size="6"> internet connected</h2>" else echo "offline" echo "<h2 style="background-color:#ff0000"><font size="6"> internet not connected</h2>" fi } ##### main cat <<- _eof_ <html> <head> <title style="background-color:#0000ff">$title</title> </head> <body> <h1>$title</h1> <p>$time_stamp</p> $(net_info)   </body> </html> _eof_ 

thanks jszameister works when moved line inside function that

function net_info { echo -e "get http://google.com http/1.0\n\n" | nc google.com 80 > /dev/null 2>&1 if [ $? -eq 0 ]; echo "online" echo "<h2 style="background-color:#00ff00"><font size="6"> internet connected</h2>" else echo "offline" echo "<h2 style="background-color:#ff0000"><font size="6"> internet not connected</h2>" fi } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -