You are not logged in.
Pages: 1
What's a simple bash script checking if online/connected before running wget?
Markku
Offline
I suppose you could run a `ping -c1 www.google.com` and check the return code.
v/r
Suds
Offline
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
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
wget --spider www.blalblabla.com
checks if the site exists without downloading and returns 0 if it does.
Offline
Good one Penguin - I never knew that about wget!
v/r
Suds
Offline
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.
Markku
Offline
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
wget is --timeout=seconds
Offline
You can also use fping package.
Offline
Thanks guys!
wget --output-file=/tmp/check.tmp --timeout=15 --spider www.user-contributions.org
Markku
Offline
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
Pages: 1