Script to connect to internet at bootup

Olivier Cailloux olivier.cailloux at gmail.com
Fri Mar 4 19:48:03 UTC 2011


-- Original post (I shouldn't have snipped it):

Hello list,

In the building where I live we have a bit of a "special" Internet
access, i.e. we need to authenticate on an Internet page at a given URL.
This is a simple HTML POST. It must be done at about each boot up. I
have no idea how the network "knows" that I rebooted my computer, but
apparently it knows as if I don't re-authenticate I have no Internet
access. Anyway, that's not the point.

I'd like to have a script that authenticates me each time I (re)boot.
Writing the script is not a problem: just a curl command. However, I
wonder how to set up my system so that the script is run at every boot,
and at the correct time, e.g. the DNS service must be loaded otherwise
curl simply fails. Currently I have put the script in/etc/profiles.d/,
but it often ends up being run too soon. I'd like to find some clean
solution, in line with the usual administrator best practices. The
script should be set up system wide, not for my personal use only. Maybe
that involves adding the script to init.d and set up the dependencies
right? Is there an alternative way that would be considered cleaner (or
simpler)? If that is indeed the way to go, which exactly is the
dependency? (I should be able to state that the script must be run "only
when the network is ready", but I don't know what that exactly means wrt
the available services.) Also, how to turn a simple one-line command
into an init.d script? I can copy a daemon file from an other service
and tweak it for my usage but 1) it seems unneedingly complex compared
to the fact that what I want to run is a simple command; 2) these are
daemon startup scripts, where a lot of options do not make sense for my
simple script (e.g. my script can't be "stopped" or "restarted", only
being "run").

Any reference to a tutorial on that subject or advices would be appreciated.
--

Le 04/03/2011 19:56, Smoot Carl-Mitchell a écrit :
> On Fri, 2011-03-04 at 19:27 +0100, Olivier Cailloux wrote:
>> Le 04/03/2011 03:36, Edwards, Todd - McClatchy Interactive a écrit :
>>> A crontab utilizing @reboot is probablly what I would use since its a simple one liner.
>> Thanks for your suggestion. Does not work. “Couldn't resolve host
>> 'internet.ciup.fr'”. (Also see the other answer.)
> How is your network configured?  From the above error, it sounds like
> your network is not up, yet when the resolver tries to resolve the host
> name.
>
Well I didn't configure anything special, just installed ubuntu, never 
touched the network configuration. It works flawlessly once I'm 
authenticated, and I can authenticate with the same script when run 
manually after boot and log in. I guess it's only a timing problem, i.e. 
my network is indeed not up yet (or at least the part related to DNS 
resolving) when the script is run by cron but it is if I manually run 
the script after having logged in.

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20110304/488868a4/attachment.html>


More information about the ubuntu-users mailing list