Re: Script to connect to internet at bootup



Le 05/03/2011 02:26, Fajar Priyanto a écrit :
On Sat, Mar 5, 2011 at 3:48 AM, Olivier Cailloux
<olivier.cailloux@xxxxxxxxx> wrote:
Also the script works if I set a delay of 15 seconds before running it. But
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
So, you are correct. It's timing issue. Delaying the script makes it work.
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.

I tried the following script, which does not work.
--
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



Relevant Pages

  • Re: Is there a way to forward only email to someone@AOL.com to a s
    ... Also on this site there is a way to test if your script ... map to ourdomain.com in DNS ... you for helping us to solve our SBS problems. ... I have other people on Verizon and they can send to AOL.com users. ...
    (microsoft.public.windows.server.sbs)
  • Re: Dynamic DNS management
    ... One of the irritations is that with a dynamic DNS, ... the IP addresses for the authoritative DNS server of multiple domains ... In the script, the above line is repeated for each domain; ... Perl has very good pattern matching. ...
    (comp.lang.perl.misc)
  • Solaris tuning
    ... new DNS infrastructure. ... behavior for me) that needs to be increased so this script can take ... server 198.18.0.12 ... def start: ...
    (comp.unix.solaris)
  • nsupdate(8) rc.d Script
    ... Subject: nsupdaterc.d Script ... As I was setting up DNS for IPv6 on a test network, ... And the script is not optimized to do the updates in the ...
    (freebsd-current)
  • Re: script to listen
    ... You can either create your script and schedule it or do a loop. ... periodically monitor free disk space until the amount of free disk space ... To create a loop that runs forever, you simply specify a loop condition that ...
    (microsoft.public.windows.server.scripting)