You are not logged in.

#1 2008-02-18 23:06:05

baro
Member
From: Germany
Registered: 2008-02-18
Posts: 23

How to start a skript after network interface is started ?

Hello,

I am new to Archlinux and don't know the Archlinux way to start a script after wpa_supplicant has connected my wlan0 device to an AP.
I want to start "firestarter" after wlan0 is up because starting firestarter via an daemon entry in rc.conf isn't working as wlan0 isn't up at that moment.
Is there something like an "ifup" script-/directory - I can't find it ?

Best regards,

Ingo

Offline

#2 2008-02-18 23:12:40

bender02
Member
From: UK
Registered: 2007-02-04
Posts: 1,328

Re: How to start a skript after network interface is started ?

I don't know of an "official" way to start something automatically after something happens. The way I'd do it is to run a script from /etc/rc.local (that gets executed at the end of init process), which would have something like this in it:

#!/bin/bash
until [ `wpa_cli -i wlan0 status | grep COMPLETED | wc -l` -eq 1 ]
do
        sleep 5
done;
-> here the command to start firestarter (probably /etc/rc.d/firestarter start)

What it does is that it polls wpa supplicant each 5 seconds to see if it's connected to an AP. When it is, the script continues to the last line, which runs firestarter. (EDIT: cleanup)

Another EDIT: now I see a better way to do it: if you are using iphitus' netcfg2 to bring up the network (aka network profiles/scripts wiki), then you can add the command to start firestarter (/etc/rc.d/firestarter start) to the field "POST_UP" in your configuration profile (should be some file in /etc/network.d/). Have a look at /etc/network.d/examples/complete.example.

Last edited by bender02 (2008-02-18 23:18:52)

Offline

#3 2008-02-19 08:26:35

baro
Member
From: Germany
Registered: 2008-02-18
Posts: 23

Re: How to start a skript after network interface is started ?

I have tested both without success.

Your script fails for me when invoked from rc.local with a message about a problem with wpa_cli ... I guess wpa_cli reports an error when wpa_supplicant isn't already working - I'll take a closer look at this problem this evening. But thank you a lot for this example, I didn't know of wpa_cli.

Uhh.. I just recognized that I did use the out of date page http://wiki.archlinux.org/index.php/Wpa … rk_Profile
to configure my wlan - I'll give it a try with the wiki link you suggested and report back.

Offline

#4 2008-02-19 10:32:01

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: How to start a skript after network interface is started ?

To clarify the above - the wiki page you were using refers to the current network scripts, and is still valid. Using that setup, placing 'firestarter' after 'network' in the rc.conf DAEMONS array should work.

However, the link bender02 gave concerns netcfg2, the new version of the network profile scripts, and is recommended. In this case, after configuration, you can place 'firestarter' after 'net-profiles' in the DAEMONS array.

Offline

#5 2008-02-19 11:33:40

baro
Member
From: Germany
Registered: 2008-02-18
Posts: 23

Re: How to start a skript after network interface is started ?

Is there something like a debug mode (something like the @ or ! flag - bash -vx) or log for the DAEMONS array calls or the firestarter call in the DAEMONS array so I can check what really is failing ?
Currently the boot screen scrolls by at a speed that makes it impossible to read the error message (if there is any) and forwards me directly to the console login prompt.

My wild guess is that the firestarter script fails to locate the wlan0 device and its IP as I use wpa_supplicant to connect to the AP and dhcp to request an IP from it and it may not be finished with it tasks when firestarter gets called - even with firestarter as the last entry in DAEMONS.

Is it possible to invoke firestarter after dhcpcd got an IP for my wlan0 device ? That would sound like the best solution - I have no clue if POST_UP would/could take care of of that.

Don't get me wrong - I don't have a problem with writing a small script for getting this done in rc.local - I am just interested how it is supposed to work by Archlinux and I think it is no unusal wireless setup.

Offline

#6 2008-02-19 12:11:02

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: How to start a skript after network interface is started ?

The way I described it is the way it is supposed to work. If there is a delay before your device gets an IP, try using POST_UP in your profile.

Offline

#7 2008-02-19 16:37:45

bender02
Member
From: UK
Registered: 2007-02-04
Posts: 1,328

Re: How to start a skript after network interface is started ?

One trick I learned recently is that if you want to wait at the end of the init process to get a chance to read the error messages, just put a line with 'read' into your rc.local. That will wait for a keypress before it clears the screen and shows the login prompt.

Offline

#8 2008-02-19 21:48:06

baro
Member
From: Germany
Registered: 2008-02-18
Posts: 23

Re: How to start a skript after network interface is started ?

The new version of the network profile scripts works great. POST_UP did the trick for firestarter too.

The only problem setting up a profile skript with wpa_supplicant was that I had to specify ESSID even when wpa_supplicant should
select one. I found a post in the forum where someone mentioned to set ESSID=* to get this working.
This little piece of information seems to be missing in the wiki/man page/examples.

Thanks both of you for your kind help.

Offline

Board footer

Powered by FluxBB