LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-19-2005, 11:19 AM   #1
Aidan81
LQ Newbie
 
Registered: Feb 2005
Posts: 4

Rep: Reputation: 0
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.
 
Old 02-19-2005, 11:39 AM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,058

Rep: Reputation: 295Reputation: 295Reputation: 295
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.
 
Old 02-19-2005, 05:03 PM   #3
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 53
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.
 
Old 02-20-2005, 10:28 AM   #4
Aidan81
LQ Newbie
 
Registered: Feb 2005
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
Old 02-20-2005, 10:53 AM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,058

Rep: Reputation: 295Reputation: 295Reputation: 295
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.
 
Old 02-20-2005, 12:06 PM   #6
Aidan81
LQ Newbie
 
Registered: Feb 2005
Posts: 4

Original Poster
Rep: Reputation: 0
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....
 
Old 02-20-2005, 02:57 PM   #7
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 53
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.
 
Old 02-20-2005, 03:50 PM   #8
Aidan81
LQ Newbie
 
Registered: Feb 2005
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM


All times are GMT -5. The time now is 02:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration