Re: Script to connect to internet at bootup
- From: Olivier Cailloux <olivier.cailloux@xxxxxxxxx>
- Date: Sat, 05 Mar 2011 16:53:42 +0100
Le 05/03/2011 02:26, Fajar Priyanto a écrit :
On Sat, Mar 5, 2011 at 3:48 AM, Olivier CaillouxI tried the following script, which does not work.
<olivier.cailloux@xxxxxxxxx> wrote:
Also the script works if I set a delay of 15 seconds before running it. ButSo, you are correct. It's timing issue. Delaying the script makes it work.
I'd like to find some clean way of configuring this, that is, I'd like to be
able to specify to run the script only when "everything needed" (meaning, I
guess: the DNS system) is ready. That's why I thought I'd use the dependency
mechanism of init.d (see above the original post), but there may exist
better approaches.
Olivier
Well, if you don't want to use the delay method, we can use command to
resolve something, and if it doesn't succeed, keep trying until
successful, then run the authenticate script.
Some example I found in the net:
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
Read more: http://www.linuxscrew.com/2009/04/02/tiny-bash-scripts-check-internet-connection-availability/#ixzz1FgTn9iYo
Also, I think better write all those thing in a separate script and
call it through rc.local instead for tidiness.
--
echo "${0}" start > /home/olivier/Logiciels/FBL-wg-auth-out.log
wget --tries=10 --retry-connrefused --timeout=5 http://internet.ciup.fr/ 1>> /home/olivier/Logiciels/FBL-wg-auth-out.log 2>> /home/olivier/Logiciels/FBL-wg-auth-err.log
if [ "$?" -ne "0" ]; then
echo "Wget failed, ending." >> /home/olivier/Logiciels/FBL-wg-auth-err.log
else
echo "Wget succeeded, continuing." >> /home/olivier/Logiciels/FBL-wg-auth-out.log
curl (...)
fi
echo "${0}" end >> /home/olivier/Logiciels/FBL-wg-auth-out.log
--
Does not work because wget considers a DNS error as a permanent error and does not retry after the first failure.
So one way to go would be to further explore that suggestion by testing in some loop, or with some other tools, whether the DNS resolves (some hints are given on the page you suggested). Or simply run my curl command repeatedly in a loop until it works (with a limit on the number of tries). I'll do this if I don't get any better suggestion on this list.
However my one-line script is becoming more and more complex, it feels strange to me to have to manually implement a check in a loop just to specify a dependency on the DNS service. I still wonder if I could use something like the dependency mechanism init.d uses (AFAIU), or anything of the same kind.
(Note that my question is not only about solving my specific current problem but also about learning how to effectively script things on a linux system.)
Olivier
--
ubuntu-users mailing list
ubuntu-users@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
- Follow-Ups:
- Re: Script to connect to internet at bootup
- From: Fajar Priyanto
- Re: Script to connect to internet at bootup
- References:
- Re: Script to connect to internet at bootup
- From: Edwards, Todd - McClatchy Interactive
- Re: Script to connect to internet at bootup
- From: Olivier Cailloux
- Re: Script to connect to internet at bootup
- From: Smoot Carl-Mitchell
- Re: Script to connect to internet at bootup
- From: Olivier Cailloux
- Re: Script to connect to internet at bootup
- From: Fajar Priyanto
- Re: Script to connect to internet at bootup
- Prev by Date: how to make symbols used in differential equations and maths etc character map information needed
- Next by Date: Re: A Moving to Linux Question
- Previous by thread: Re: Script to connect to internet at bootup
- Next by thread: Re: Script to connect to internet at bootup
- Index(es):
Relevant Pages
|