You are not logged in.

#1 2005-11-08 07:41:03

rasat
Forum Fellow
From: Finland, working in Romania
Registered: 2002-12-27
Posts: 2,176
Website

How to check if online?

What's a simple bash script checking if online/connected before running wget?

Offline

#2 2005-11-08 07:44:15

sudman1
Member
From: Huntingdon, UK
Registered: 2005-02-18
Posts: 143

Re: How to check if online?

I suppose you could run a `ping -c1 www.google.com` and check the return code.


v/r
Suds

Offline

#3 2005-11-08 07:54:48

High|ander
Member
From: Skövde, Sweden
Registered: 2005-10-28
Posts: 188
Website

Re: How to check if online?

Hm, the only problem is when servers block the ICMP packets... Then the server won't respond. But i don't know a better solution sorry


When death smiles at you, all you can do is smile back!
Blog

Offline

#4 2005-11-08 09:42:22

Cam
Member
From: Brisbane, Aus
Registered: 2004-12-21
Posts: 658
Website

Re: How to check if online?

Google don't block ICMP packets though and it's the most reliable site I can think of. You could always check a couple of top sites if you wanted to be sure though. There are so many different ways to get net access, the best way would probably be to ping a site and see if you can or not.

Offline

#5 2005-11-08 10:59:57

T-Dawg
Forum Fellow
From: Wilmington, NC
Registered: 2005-01-29
Posts: 2,734

Re: How to check if online?

wget --spider www.blalblabla.com

checks if the site exists without downloading and returns 0 if it does.

Offline

#6 2005-11-08 11:06:37

sudman1
Member
From: Huntingdon, UK
Registered: 2005-02-18
Posts: 143

Re: How to check if online?

Good one Penguin - I never knew that about wget!


v/r
Suds

Offline

#7 2005-11-08 11:12:47

High|ander
Member
From: Skövde, Sweden
Registered: 2005-10-28
Posts: 188
Website

Re: How to check if online?

Okay, that was verry good, didn't know that, thanks!


When death smiles at you, all you can do is smile back!
Blog

Offline

#8 2005-11-08 11:30:31

rasat
Forum Fellow
From: Finland, working in Romania
Registered: 2002-12-27
Posts: 2,176
Website

Re: How to check if online?

Both ping and wget works. Is there a way to speed up the timing. As default, it takes about 1 minute to get an error reply when no connection.

Offline

#9 2005-11-08 11:36:28

sudman1
Member
From: Huntingdon, UK
Registered: 2005-02-18
Posts: 143

Re: How to check if online?

with ping you can change the timeout with the -t  switch.. I think the argument is in millis.
looking at the wget man page, it has a -t switch for the number of tries - but I don't know how that works with --spider.


v/r
Suds

Offline

#10 2005-11-08 11:48:19

T-Dawg
Forum Fellow
From: Wilmington, NC
Registered: 2005-01-29
Posts: 2,734

Re: How to check if online?

wget is --timeout=seconds

Offline

#11 2005-11-08 12:43:17

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: How to check if online?

You can also use fping package.

Offline

#12 2005-11-08 13:24:03

rasat
Forum Fellow
From: Finland, working in Romania
Registered: 2002-12-27
Posts: 2,176
Website

Re: How to check if online?

Thanks guys!

wget --output-file=/tmp/check.tmp --timeout=15 --spider www.user-contributions.org

Offline

#13 2005-11-08 20:21:45

T-Dawg
Forum Fellow
From: Wilmington, NC
Registered: 2005-01-29
Posts: 2,734

Re: How to check if online?

rasat wrote:

Thanks guys!

wget --output-file=/tmp/check.tmp --timeout=15 --spider www.user-contributions.org

Instead of parsing an output file for the results you can check the return status:

wget --timeout=15 --spider www.user-contributions.org
if [ $? -eq 0 ]; then
echo "URL not found or no connectivity"
fi

you can append &>/dev/null to the wget line to not display standard output or error.

Offline

Board footer

Powered by FluxBB