Sometimes it is necessary to check whether server you want to run some big bash script is connected to Internet. Usually it makes sense while running scripts periodically using cron.  Below is the tiny bash script for this purpose:

#!/bin/bash

WGET="/usr/bin/wget"

$WGET -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
if [ ! -s /tmp/index.google ];then
	echo "no"
else
	echo "yes"
fi

As you see it tries to download google’s index page, if it’s not empty script returns “yes”, if there is not Internet connection available script will return “no”. If it is impossible to fetch the page in more than 5 seconds script will return “no” as well.

Anything to add? You are welcome! :)

 

144 Comments

 

  1. April 21, 2011  7:59 am by zynga poker bot 2011 Reply

    Hey would you mind stating which blog platform you're working with? I'm going to start my own blog soon but I'm having a difficult time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I'm looking for something unique. P.S Apologies for being off-topic but I had to ask!

  2. April 21, 2011  4:08 pm by Perry Belcher Reply

    Of course I like your website, but you need to check the spelling on several of your posts. Many of them are rife with spelling issues and I find it very silly to tell you. On the other hand I will definitely come again again!

  3. April 23, 2011  6:54 pm by cpanel Reply

    I think other site owners should take this site as an model - very clean and magnificent style and design, not to mention the content. You're an expert in this area!

  4. April 26, 2011  9:49 pm by finding morels Reply

    As a web-site owner I believe the material here is reallygreat. I appreciate it for your hard work. You should keep it up forever! Best of luck..

  5. April 28, 2011  10:41 am by What is ADD Reply

    Thank you for a very informative website. What else could I get that kind of information written in such an ideal means? I have a challenge that I am simply now operating on, and I've been on the look out for such info.

  6. April 28, 2011  10:51 pm by car insurance Reply

    As a site owner I believe the material here is reallywonderful. I appreciate it for your time. You should keep it up forever! Best of luck.

  7. May 2, 2011  2:56 am by Highlands Ranch Restaurant Reply

    I was just searching for this information for a while. After six hours of continuous Googleing, at last I got it in your web site. I wonder what's the Google's problem that doesn't rank this type of informative sites closer to the top. Generally the top sites are full of garbage.

  8. May 2, 2011  11:39 pm by costa rica luxury hotel Reply

    I truly appreciate this post. I’ve been looking everywhere for this! Thank goodness I found it on Google. You've made my day! Thx again..

  9. May 3, 2011  4:27 am by buy vegemite Reply

    Greetings from Australia. Great write-up. I am a regular visitor of your website and appreciate you taking the time to maintain the excellent content. I'll be a frequent visitor for a long time.

  10. May 3, 2011  4:30 am by buy vegemite Reply

    Greetings from Australia. Good write-up. I’m a regular visitor of your site and appreciate you taking the time to maintain the nice site. I'll be a regular visitor for a long time.

  11. May 3, 2011  4:01 pm by achieve anything Reply

    I was just searching for this information for a while. After 6 hours of continuous Googleing, finally I got it in your website. I wonder what's the Google's problem that does not rank this kind of informative websites closer to the top. Normally the top web sites are full of garbage.

  12. May 9, 2011  1:16 pm by deadbeat millionaire review Reply

    I was just searching for this deadbeat millionaire review info for some time. After six hours of continuous Googleing, at last I got deadbeat millionaire bonus it in your site. I wonder what is the Google's issue that does not rank this kind of informative deadbeat millionaire review and bonus websites closer to the top. Generally the top web sites are full of garbage.

  13. May 10, 2011  12:17 pm by financial advisor Sydney Reply

    Hello there. I found your website by the use of Google while searching for a related subject on financial advisor Sydney, your web site got here up. It looks good. I have bookmarked it in my google bookmarks under Sydney financial advisor to visit later.

  14. May 26, 2011  5:26 pm by Los Angeles pool builder Reply

    This is the proper weblog for anybody who wants to search out out about this topic. You realize a lot its virtually hard to argue with you (not that I truly would want…HaHa). http://www.allstatepools.com You undoubtedly put a brand new spin on a topic thats been written about for years. Great stuff, simply nice!

  15. June 4, 2011  4:20 pm by Inger Schauf Reply

    "This is a topic close to my heart cheers, where are your contact details though?"

  16. June 7, 2011  8:08 pm by Wywasokiz Reply

    If there is an overnight milk with cucumber, your Finnish plumbing quickly pay for itself! Dinner was excellent, especially the hostess failed mayonnaise Why men feet are freezing in winter, but women do not?? Because men heating lousy, and women bitching yany Russian hacker practically invincible! What kind of roof do not like to drive fast? There is nothing worse than to cheat a woman ... But there is nothing nicer when it turns out.

  17. March 2, 2012  8:59 am by youtube clone Reply

    You could certainly see your expertise within the paintings you write. The arena hopes for even more passionate writers such as you who aren't afraid to say how they believe. All the time follow your heart.

  18. March 2, 2012  9:01 am by youtube scripts Reply

    Hi, i feel that i noticed you visited my site thus i came to go back the desire?.I'm trying to find things to enhance my website!I suppose its adequate to use a few of your concepts!!

  19. March 30, 2012  7:32 pm by fruit mocking party Reply

    I really like your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz respond as I'm looking to construct my own blog and would like to find out where u got this from. many thanks

  20. June 8, 2012  7:22 am by List Your Business Free! Reply

    I've seen this post and script for first time! Thanks for sharing the Unique information

  21. June 23, 2012  11:38 am by Chadwick Silha Reply

    Wonderful goods from you, man. I've understand your stuff previous to and you are just too wonderful. I actually like what you've acquired here, really like what you are saying and the way in which you say it. You make it enjoyable and you still take care of to keep it sensible. I can't wait to read much more from you. This is actually a wonderful site.

  22. Pingback : Pray » Answers Archive » louis vuitton site officiel lunette louis vuitton Territory network contract p

  23. Pingback : ralph lauren abercrombie and fitch paris National Security Blog | tarimcevap.com

Leave a reply

 

Your email address will not be published.