My Wireless Script Wont Work.....anyone??

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.

Don't use sudo in the script. As root, change its ownership to root and then set the "set user-ID" bit on it

chown root script
chmod u+s script

Hope that helps.

Jerry

Setting the SUID bit does not work for scripts on most systems (including Linux).

However, you are right that sudo should not be in the script. The script should be run with "sudo SCRIPT".

I wasn't aware of that! Why's it still there? It's certainly there and works on Solaris.

To endorse cfajohnson. Set UID and set GID on scripts does not elevate
the privilege of the commands within that script.

thanks, tried it but still not working....

What did you try? And what does "not working" mean exactly?

i tried the what jerry suggested but im still getting the same results. if i run each line seperate in a terminal everything works fine. but when i put it all in a script i get the same results. i set execute permissions, checked my etc/networks file, removed sudo and ran as root but still no go.

puzzling.......