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. Pingback : Doll Idea | adidas wings 2096oQ

  2. Pingback : ?????? ?? HAcrL | etenjRi

  3. Pingback : amj louis vuitton handbags sjju

  4. May 24, 2013  6:16 pm by karen millen ebay Reply

    Good day! I could have sworn I've been to this website before but after reading through some of the post I realized it's new to me. Anyways, I'm definitely glad I found it and I'll be book-marking and checking back often!

  5. Pingback : burberry fv2O | kifo5898

  6. Pingback : ?????? ?? rILYc | e8nfbN1

  7. Pingback : louis vuitton outlet Gucci outlet handbags cheap oakleys gyqb etbkli | hhhasaey545

  8. Pingback : ?????? ?? gRwIq | H1ueTpbZy

  9. May 29, 2013  1:59 am by karen millen womens fashion dresses online Reply

    Does your blog have a contact page? I'm having a tough time locating it but, I'd like to send you an email. I've got some ideas for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it expand over time.

  10. Pingback : la guerre des prix « people0155momen

  11. May 30, 2013  2:11 am by oakley gloves Reply

    Undeniably imagine that that you said. Your favorite reason seemed to be at the net the easiest factor to take into accout of. I say to you, I certainly get irked at the same time as folks think about concerns that they just don't know about. You controlled to hit the nail upon the top neatly as|and also|and} defined out the entire thing with no need side-effects , folks could take a signal. Will probably be again to gt more. Thank you

  12. Pingback : discount golf equipment louis vuitton handbags the coach purses are created | ?????????????

  13. Pingback : nike air max 59588 | Fashion a Street

  14. May 31, 2013  9:46 am by karen millen designer women clothing Reply

    I do not even know the way I finished up here, however I thought this put up used to be good. I do not understand who you are however definitely you are going to a famous blogger when you are not already. Cheers!

  15. June 1, 2013  2:15 am by custom oakleys Reply

    Wow, that's what I was searching for, what a data! present here at this website, thanks admin of this web site.

  16. June 1, 2013  10:08 am by oakley straight Reply

    I visit each day a few sites and blogs to read articles, except this website offers quality based posts.

  17. June 3, 2013  12:43 am by longchamp pliage prix Reply

    I visited various web sites but the audio quality for audio songs current at this website is truly wonderful.

  18. June 3, 2013  12:45 am by faience longchamp Reply

    I'm impressed, I must say. Rarely do I come across a blog that's both equally educative and amusing, and without a doubt, you have hit the nail on the head. The problem is something that not enough people are speaking intelligently about. Now i'm very happy that I stumbled across this during my hunt for something regarding this.

  19. June 3, 2013  12:46 am by pochette homme longchamp Reply

    For most up-to-date information you have to pay a visit the web and on world-wide-web I found this web site as a finest web site for most up-to-date updates.

  20. June 3, 2013  12:48 am by longchamp boutique en ligne Reply

    Very good information. Lucky me I came across your site by chance (stumbleupon). I've book marked it for later!

  21. June 3, 2013  10:00 am by sac longchamp pliage grand Reply

    think what you composed|said|published}|I think that what you composed|said|published}|I think that what you composed|said|published}|I think that what you composed|said|published}|Everything composed|said|published}} was actually very logical|made a lot of sense}. But, think about this,} what if you were to write a killer headline}?|added a little information?|wrote a catchier title?} I ain't suggesting your information is not good.|I ain't suggesting your information is not good|I mean,I don't wish to tell you how to run your blog}, however what if you added {a title|something|a headline}} that grabbed people's attention?|to possibly get a person's attention?|that makes people desire more?} I mean %BLOG_TITLE% is a little plain. You could glance at Yahoo's home page and note how they create} news titles to get people to open the links. You might add a video or a pic or two to get people excited about what you've got to say. In my opinion, it could bring your {posts|blog} a little bit more interesting.

Leave a reply

 

Your email address will not be published.