FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 03-04-2011, 01:18 AM
Olivier Cailloux
 
Default Script to connect to internet at bootup

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.
Olivier


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

Fri Mar 4 03:30:01 2011
Return-path: <ubuntu-users-bounces@lists.ubuntu.com>
Envelope-to: tom@linux-archive.org
Delivery-date: Fri, 04 Mar 2011 03:25:50 +0200
Received: from chlorine.canonical.com ([91.189.94.204]:35409)
by s2.java-tips.org with esmtp (Exim 4.69)
(envelope-from <ubuntu-users-bounces@lists.ubuntu.com>)
id 1PvJmA-0005xd-BV
for tom@linux-archive.org; Fri, 04 Mar 2011 03:25:50 +0200
Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com)
by chlorine.canonical.com with esmtp (Exim 4.71)
(envelope-from <ubuntu-users-bounces@lists.ubuntu.com>)
id 1PvKsw-0000ix-1X; Fri, 04 Mar 2011 02:36:54 +0000
Received: from exprod8og106.obsmtp.com ([64.18.3.92])
by chlorine.canonical.com with smtp (Exim 4.71)
(envelope-from <tedwards@mcclatchyinteractive.com>)
id 1PvKst-0000hq-Jz
for ubuntu-users@lists.ubuntu.com; Fri, 04 Mar 2011 02:36:51 +0000
Received: from source ([63.81.161.29]) by exprod8ob106.postini.com
([64.18.7.12]) with SMTP
ID DSNKTXBQQZLOgsLnR2TgB9+5DWCc2syMyyQQ@postini.com;
Thu, 03 Mar 2011 18:36:51 PST
Received: from mcc-sacgw02.mcclatchy.local (mcc-sacgw02.mcclatchy.local
[10.194.2.58])
by mx2.mcclatchy.com (8.14.3/8.14.3) with ESMTP id p242SB9i002327
for <ubuntu-users@lists.ubuntu.com>;
Thu, 3 Mar 2011 18:28:11 -0800 (PST)
X-AuditID: 0ac2023a-b7c3dae000002385-0b-4d70503bb2e6
Received: from mcc-exchcas01.mcclatchy.local ( [10.194.2.53])
by mcc-sacgw02.mcclatchy.local (Symantec Brightmail Gateway) with SMTP
id 74.F9.09093.B30507D4; Thu, 3 Mar 2011 18:36:43 -0800 (PST)
Received: from MCC-EXCHCCR.mcclatchy.local ([fe80::d9e3:c0a6:93b:1306]) by
mcc-exchcas01.mcclatchy.local ([::1]) with mapi;
Thu, 3 Mar 2011 18:36:43 -0800
From: "Edwards, Todd - McClatchy Interactive"
<tedwards@mcclatchyinteractive.com>
To: "Ubuntu user technical support, not for general discussions"
<ubuntu-users@lists.ubuntu.com>
Date: Thu, 3 Mar 2011 18:36:43 -0800
Subject: Re: Script to connect to internet at bootup
Thread-Topic: Script to connect to internet at bootup
Thread-Index: AcvaEs4/C5N2beQeT5CLNVnTIiRcUgAAjEqz
Message-ID: <esl0v2jqeyg1udi0qem8yauf.1299206211946@email.andr oid.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
acceptlanguage: en-US

MIME-Version: 1.0
X-Brightmail-Tracker: AAAAAA==
X-Logged: Logged by mx2.mcclatchy.com as p242SB9i002327 at Thu Mar 3 18:28:11
2011
X-BeenThere: ubuntu-users@lists.ubuntu.com
X-Mailman-Version: 2.1.13
Precedence: list
Reply-To: "Ubuntu user technical support,
not for general discussions" <ubuntu-users@lists.ubuntu.com>
List-Id: "Ubuntu user technical support,
not for general discussions" <ubuntu-users.lists.ubuntu.com>
List-Unsubscribe: <https://lists.ubuntu.com/mailman/options/ubuntu-users>,
<mailto:ubuntu-users-request@lists.ubuntu.com?subject=unsubscribe>
List-Archive: <https://lists.ubuntu.com/archives/ubuntu-users>
List-Post: <mailto:ubuntu-users@lists.ubuntu.com>
List-Help: <mailto:ubuntu-users-request@lists.ubuntu.com?subject=help>
List-Subscribe: <https://lists.ubuntu.com/mailman/listinfo/ubuntu-users>,
<mailto:ubuntu-users-request@lists.ubuntu.com?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: ubuntu-users-bounces@lists.ubuntu.com
Errors-To: ubuntu-users-bounces@lists.ubuntu.com

A crontab utilizing @reboot is probablly what I would use since its a simple one liner.

Sent from my mobile.

Olivier Cailloux <olivier.cailloux@gmail.com> wrote:


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.
Olivier


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-04-2011, 01:44 AM
Fajar Priyanto
 
Default Script to connect to internet at bootup

On Fri, Mar 4, 2011 at 10:18 AM, Olivier Cailloux
<olivier.cailloux@gmail.com> wrote:
> fails. Currently I have put the script in /etc/profiles.d/, but it often
> ends up being run too soon.

/etc/rc.local is the latest to be run during reboot. You can put it there.

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-04-2011, 04:36 PM
Olivier Cailloux
 
Default Script to connect to internet at bootup

Thanks for the answer. Just tried it, to no avail.

Le 04/03/2011 03:44, Fajar Priyanto a écrit :

On Fri, Mar 4, 2011 at 10:18 AM, Olivier Cailloux
<olivier.cailloux@gmail.com> wrote:

fails. Currently I have put the script in /etc/profiles.d/, but it often
ends up being run too soon.

/etc/rc.local is the latest to be run during reboot. You can put it there.

I added the following three lines into rc.local (originally untouched,
contained only the usual exit 0 which I left at the end of the file).

echo coucou > /home/olivier/Logiciels/FBL-rc-auth-log.log
curl -d 'admin_id=XXX' -d 'admin_pw=XXX'
http://internet.ciup.fr/web_auth/index.html -o
/home/olivier/Logiciels/FBL-rc-auth-res.log 1>>
/home/olivier/Logiciels/FBL-rc-auth-out.log 2>>
/home/olivier/Logiciels/FBL-rc-auth-err.log

echo fin >> /home/olivier/Logiciels/FBL-rc-auth-log.log

Having deleted the files /home/olivier/Logiciels/FBL-rc*, I reboot.
After the reboot: FBL-rc-auth-out.log is empty. FBL-rc-auth-err.log
contains “curl: (6) Couldn't resolve host 'internet.ciup.fr'”.
FBL-rc-auth-log.log contains only “coucou”, which is pretty strange,
meaning that apparently the script did not complete. FBL-rc-auth-res.log
does not exist.


Running 'bash /etc/rc.profile' from a terminal after the boot is
completed executes the script correctly (output files are set as
expected) and correctly authenticates me.

Olivier


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-04-2011, 05:27 PM
Olivier Cailloux
 
Default Script to connect to internet at bootup

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.)

Olivier


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-04-2011, 05:56 PM
Smoot Carl-Mitchell
 
Default Script to connect to internet at bootup

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.

--
Smoot Carl-Mitchell
System/Network Architect
voice: +1 480 922-7313
cell: +1 602 421-9005
smoot@tic.com


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-04-2011, 06:48 PM
Olivier Cailloux
 
Default Script to connect to internet at bootup

-- 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





--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-04-2011, 07:55 PM
Colin Law
 
Default Script to connect to internet at bootup

On 4 March 2011 19:48, Olivier Cailloux <olivier.cailloux@gmail.com> wrote:
> ...
> 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.

Have you got 'Available to all users' ticked for your network
connection? Otherwise the network will not be up till after you
login. Right click on the NM applet > Edit Connections > select the
network and Edit.

If you can't find another solution you might like to look at WICD
rather than Network Manager. It has the ability to specify scripts to
run after the connection comes up, so you could do your authentication
there.

Colin

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-05-2011, 12:26 AM
Fajar Priyanto
 
Default Script to connect to internet at bootup

On Sat, Mar 5, 2011 at 3:48 AM, Olivier Cailloux
<olivier.cailloux@gmail.com> 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.

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-05-2011, 02:05 PM
Olivier Cailloux
 
Default Script to connect to internet at bootup

Le 04/03/2011 21:55, Colin Law a crit :

On 4 March 2011 19:48, Olivier Cailloux<olivier.cailloux@gmail.com> wrote:

...
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.

Have you got 'Available to all users' ticked for your network
connection? Otherwise the network will not be up till after you
login. Right click on the NM applet> Edit Connections> select the
network and Edit.

It is ticked.

If you can't find another solution you might like to look at WICD
rather than Network Manager. It has the ability to specify scripts to
run after the connection comes up, so you could do your authentication
there.
Thanks for that suggestion. However I'll try to explore less drastic
solutions first...

Olivier


Colin




--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-05-2011, 02:53 PM
Olivier Cailloux
 
Default 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@gmail.com> 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@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 09:04 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org