Results 1 to 2 of 2
ive been trying to write a simple (at least i thought it was) script to launch my wireless usb under ubuntu with kde. im using nano.
when i run it ...
- 01-16-2009 #1Just Joined!
- Join Date
- Jan 2009
- Posts
- 1
My wireless script wont run /w caveat
ive been trying to write a simple (at least i thought it was) script to launch my wireless usb under ubuntu with kde. im using nano.
when i run it from a terminal it works fine, but it just wont run from the script. there is a caveat, but first heres the script.
-------------------------------
#!/bin/bash
sudo ifconfig wlan1 up
sudo iwpriv wlan1 set AuthMode=WPAPSK
sudo iwpriv wlan1 set EncrypType=TKIP
sudo iwpriv wlan1 set WPAPSK=1111111111
sudo iwpriv wlan1 set SSID=network
sudo iwpriv wlan1 set NetworkType=Infra
sudo dhclient wlan1
---------------------------
this is the output
There is already a pid file /var/run/dhclient.pid with pid 13451
Internet Systems Consortium DHCP Client V3.0.6
Copyright 2004-2007 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/wlan1/(mac is here)
Sending on LPF/wlan1/(mac is here)
Sending on Socket/fallback
DHCPREQUEST of 192.168.0.444 on wlan1 to 255.255.255.255 port 67
DHCPREQUEST of 192.168.0.444 on wlan1 to 255.255.255.255 port 67
DHCPDISCOVER on wlan1 to 255.255.255.255 port 67 interval 6
DHCPDISCOVER on wlan1 to 255.255.255.255 port 67 interval 9
DHCPDISCOVER on wlan1 to 255.255.255.255 port 67 interval 9
DHCPDISCOVER on wlan1 to 255.255.255.255 port 67 interval 7
No DHCPOFFERS received.
Trying recorded lease 192.168.1.444
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
--- 192.168.0.1 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
No working leases in persistent database - sleeping
--------------------------
now heres the twist:
sometimes it asks for a password, sometimes it doesnt
also, if i run the script up to here:
sudo iwpriv wlan1 set NetworkType=Infra
stop it, and run sudo dhclient wlan1 in a terminal, it works!
ive tried running it with sh script, ./script but still no joy. its probably something simple im just missing but im stumpped.
thanx if anyone has any ideas.
- 01-17-2009 #2Linux Guru
- Join Date
- Jan 2009
- Location
- Dover, NH
- Posts
- 1,633
First, I suggest removing all the sudo s from the script and just running the script with sudo (sudo script). When a program or script runs with escalated privileges, so does any child it spawns, so that ought to speed things up a bit. Also, anything that runs that requires the previous command to complete successfully first, put on the same line with a && between them, as in command1 && command2. This way, command2 will not execute if command1 fails.
Then, when executing from a gui, make sure the script is in a path directory (like ~/bin) and prefix a kdesu or gksu (depending on your window manager) to the command in your shortcut/icon/menu item. (gksu /path/to/script)
As far as sometimes asking for password sometimes not, this is dependent on the last time sudo was successfully called. If it was real recent, it'll assume the user that called it before is still in front of the computer and just execute. If not, it'll ask for the password again.
On the dhclient issue: usually, if an interface it configured to use dhcp, it'll automatically be called as by ifconfig when the interface is brought up, which probably explains the "There is already a pid file /var/run/dhclient.pid with pid 13451" Of course, this can backfire on wireless connections when the interface comes up and automatically connects to the nearest unprotected access point before you have the chance to change the settings to your local WAP. If this is persistent, you could try something like killall dhclient in the script somewhere between the ifconfig and the dhclient commands.


Reply With Quote