Best way to automate connecting to a wifi network

Hello,

Because I connect to many different wireless networks around work, very often and there is no decent GUI/CUI, I currently have a few scripts that I run as su which look a little like this...

Code:
wpa_supplicant -i ath0 -c /etc/wpa_supplicant_lab7.conf & dhclient ath0

Now, this sometimes fails because dhclient times out before wpa_supplicant has made a connection...

Does anyone have any suggestions of how best to do this?

Personally OpenBSD has a great solution of allowing wpa to be configured in their ifconfig. However, I generally prefer FreeBSD :D (packages are more plentyful for one!)

Best Regards,

Karsten

EDIT: Sorry, this should be in the mobile computing section
 
Did you mean
Code:
wpa_supplicant -i ath0 -c /etc/wpa_supplicant_lab7.conf [B][color="Red"]&&[/color][/B] dhclient ath0
?

I don't know if wpa_supplicant stays in the foreground until it has a connection, but your single '&' backgrounds it immediately. You'd want wpa_supplicant to finish before dhclient tries to get an IP address.
 
Hmm, the thing is that wpa_supplicant never actually finishes, even after it is successful, it keeps running to maintain the connection.

I could use -B to make wpa_supplicant into a daemon, but then the same problem occurs and dhclient might fail.

Or will wpa_supplicant return success even though it is still running? I will give it a go as soon as I can.
 
I have no idea. You could background it, sleep for xx seconds (that's a matter of trial and error), and then run dhclient.

Code:
wpa_supplicant -i ath0 -c /etc/wpa_supplicant_lab7.conf &
sleep xx
dhclient ath0

Or if you know how to establish the existence of a connection, throw in a loop.

Code:
wpa_supplicant -i ath0 -c /etc/wpa_supplicant_lab7.conf &
while true do
if [ the connection exists ]
then
dhclient ath0
exit 0
else
sleep 10
fi
done
 
That unfortunately will cause the same problem with getting dhclient to run just whan it has connected.

What I am currently doing is (based on DutchDaemon's wait loop)

Code:
ifconfig ath0 | grep "status: associated"

and looping (with a small sleep) until this stops returning nothing.

Fully hacky! :D
 
Back
Top