Basic shell script advice needed

Booting, installing, newbie
Post Reply
Message
Author
User avatar
lvds
Posts: 340
Joined: Tue 23 Jan 2007, 15:15
Location: Near the window

Basic shell script advice needed

#1 Post by lvds »

Hi,

I need help on writing a simple shell script which tests if internet is up and running or not.
So i could be sure if a user click on an icon he will connect to a webpage or he will receive an error message stating he didn't connect to internet.

May someone help please ?

Many thanks,
Laurent.

User avatar
gary101
Posts: 555
Joined: Sun 08 Oct 2006, 09:51
Location: Boston, Lincs. UK

#2 Post by gary101 »

how are you connecting to the internet? Through a LAN (network card) , wireless or dialup?

There are lots of ways to go about this but most depend on what type of connection you have.

User avatar
lvds
Posts: 340
Joined: Tue 23 Jan 2007, 15:15
Location: Near the window

#3 Post by lvds »

Hi,

Yes that is the problem: i don't know which network support the user will have. It could be lan or wireless or dialup. first i thought at pinging www.google.com but don't know how to interpret the answer so to tell it is connected or not...

Any help is welcome...

Best regards,
Laurent.

User avatar
gary101
Posts: 555
Joined: Sun 08 Oct 2006, 09:51
Location: Boston, Lincs. UK

#4 Post by gary101 »

Something along these lines should work if all you want to do is check pings:

#!/bin/sh

HOST=www.google.com
count=2 # Send only two pings.

if [[ `ping -c $count "$HOST"` ]]
then
echo ""$HOST" You ARE connected to internet."
else
echo ""$HOST" You are NOT connected to internet."
fi

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#5 Post by rarsa »

I'd further recommend pinging the server where the page you want to show is, that way you can kill two birds with one stone.

The message could say "You are either not connected to the internet or the page you are trying to access is not accessible at the moment"
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

User avatar
lvds
Posts: 340
Joined: Tue 23 Jan 2007, 15:15
Location: Near the window

#6 Post by lvds »

Thank you very much, i will work with this ! :D

Best regards,
Laurent

Post Reply