LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell script to setup wlan (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-to-setup-wlan-292293/)

Aidan81 02-19-2005 11:19 AM

Shell script to setup wlan
 
Please excuse my ignorance as I'm rather new to Linux. After being frustrated with M$ for so long I made the decision to give the whole Linux thing a try. So far I'm loving just about everything about it and I'm learning quite a bit. My major headache so far is coming from, what else, wireless networking. I've pretty much given up on using it at home since I use WPA there and can't for the life of me get it to work with Linux. (using ndiswrapper with a broadcom chipset). I've made the attempt at using wpa_supplicant, followed multiple how-tos but just can't seem to make it work. Currently I'm attempting to write a shell script to set up my wireless configuration while at work. Everytime I reboot I need to run a few commands in the shell to get the connection up and running. I wrote a nice simple script (or so I thought) which is:

#!/bin/bash
# Mall Network Script

rm /var/run/dhcpcd-wlan0.pid
iwconfig wlan0 key s:xxxxx
iwconfig wlan0 ESSID "xxxxx"
dhcpcd wlan0

Now my problem is that I apparently need to run this with root privileges because I get this error when running it:

david@linux:~> mallnet
rm: remove write-protected regular file `/var/run/dhcpcd-wlan0.pid'? y
rm: cannot remove `/var/run/dhcpcd-wlan0.pid': Permission denied
/home/david/bin/mallnet: line 5: iwconfig: command not found
/home/david/bin/mallnet: line 6: iwconfig: command not found
/home/david/bin/mallnet: line 7: dhcpcd: command not found

I can go into the shell, su and type each line by itself, but being that I come from XP where it requires about 10 seconds to connect to any wireless network, I really would like to just get it working as a script. I know is must be something really simple I'm missing, but then again I've been using Linux for a total of about 2 days, so everything that should be simple isn't quite so.

btmiller 02-19-2005 11:39 AM

You'll need to run this script as root, not your user account. Also, it's a good idea to put the full path of shell commands into scripts, in this case iwconfig is probably /sbin/iwconfig or /usr/sbin/iwconfig.

Komakino 02-19-2005 05:03 PM

First add the parameter -f to rm so that it doesn't prompt you to delete the pid file.
Next, put your script somewhere global and do:
chmod +s mallnet
which will suid root it (i.e. nomatter who runs it, it will run as root. There are a few security implications, but nothing major). If you have an rc.local file (I use slack which is different to the other distros as it uses BSD rather than SysV init scripts) then add a line to run your script automatically.

Aidan81 02-20-2005 10:28 AM

Komakino,

Followed your advice but I am still getting an error when attempting to run the script.


david@linux:~> mallnet
bash: /usr/local/bin/mallnet: Permission denied
david@linux:~>


Once again, please excuse my ignorance if I've done something incorrectly.

Created a new script in /usr/local/bin called mallnet, using same text from previous script except adding the -f after rm in the first line. While still root chmod +s mallnet. Switch to my user account and attempt to run script and get the above error.

Thanks for the support so far.

David

btmiller 02-20-2005 10:53 AM

The kernel will not honor the SETUID bit on shell scripts (SETUID shell scripts actually have major security issues, such as being vulnerable to PATH resets, etc.). Try running it as root and see if it doesn't work. You can also use sudo to run it with root priviliges.

Aidan81 02-20-2005 12:06 PM

Ok, runs as root just fine....

Now I need to give "david" root privileges to run just that script. Added the following line to sudoers

%users david= NOPASSWD: /usr/local/bin/mallnet

and

alias mallnet='sudo /usr/local/bin/mallnet'

to my user .profile

Now I seem to have somehow taken a step backwards


david@linux:~> mallnet
rm: cannot remove `/var/run/dhcpcd-wlan0.pid': Permission denied
/usr/local/bin/mallnet: line 5: iwconfig: command not found
/usr/local/bin/mallnet: line 6: iwconfig: command not found
/usr/local/bin/mallnet: line 7: dhcpcd: command not found
david@linux:~>

If I can get this right I'll be happy for a while......until I try for WPA again....

Komakino 02-20-2005 02:57 PM

OK, a different approach. Find the local startup script...on slackware it's called rc.local. Red Hat and the others use a different approach, but there's still a start up script for local settings somewhere. Find it and add the lines from your mallnet script to that. The start up script will run as root so there won't be the permissions problems.

Aidan81 02-20-2005 03:50 PM

Komakino,

Thanks much for the tip. After inserting my lines into the boot.local script I now have access on reboot. Perhaps I'll be back with more questions when I attempt WPA on my home network. Any tips or good tutorials you can suggest for WPA setup. I'm using Suse 9.2 with ndiswrapper on a Broadcom (oh joy) internal wireless card. Have wpa_supplicant installed but it remains a mystery how to get the darn thing to work properly.

Thanks again,

David


All times are GMT -5. The time now is 09:54 AM.