LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking > Linux - Wireless Networking
User Name
Password
Linux - Wireless Networking This forum is for the discussion of wireless networking in Linux.

Notices


Reply
  Search this Thread
Old 11-16-2004, 02:59 PM   #1
andy7t
Member
 
Registered: Oct 2004
Posts: 43

Rep: Reputation: 15
Network Startup Script


Hi,

I successfully installed my DLINK wireless card on my Mandrake 10 system, and all works fine.

I start my card from shell like this:


iwconfig wlan0 channel 6
iwconfig wlan0 mode Managed
iwconfig wlan0 key off
iwconfig wlan0 enc off
iwconfig wlan0 essid conexant
<< wait a few seconds >>
iwconfig wlan0 ( to check the settings)
ifup wlan0

Great, it works :-).

Now i want to create a small script that all i have to do is double click and it starts the network.

Easy enough i thought. Just make a shell script that executes the commands above.
One problem i've found is though, those commands above need to be run as root.

How do i change users in a shell script? If i put su at the top of my script, it asks for a password, but then just stops and goes back to the command line.

Second problem. Sometimes, it takes a while for my card to 'log on' to my router.
And my AP under iwconfig wlan0 is 00:00:00:00. Sometimes that logs on in a few seconds, and the AP changes to something like 00:A5:12:AT:52, but sometimes it takes longer.
That kinda of breaks my little program. Any way to check that AP: doesn't equal 00:00, and wait until it changes?
 
Old 11-16-2004, 10:23 PM   #2
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 420Reputation: 420Reputation: 420Reputation: 420Reputation: 420
Quote:
One problem i've found is though, those commands above need to be run as root.
Well, that isn't entirely true. Yes, you do need to be root to run them, but you can give specific users permission to run commands as root using sudo. You're going to have to read the sudo man page, but the basics are that you use the visudo command to edit the /etc/sudoers file. You'll want to enter a line that looks like this:

username Machinename=NOPASSWD: /sbin/iwconfig

Machinename is usually whatever you named your machine. Run uname -a if you don't remember.

Once you've entered that line into sudoers, your user can run the iwconfig command by entering sudo iwconfig . Now if you don't have the NOPASSWD bit, you would have to enter your user password to authenticate, but if you have the NOPASSWD, the command will be run with root privileges. Obviously you are going to want to be careful which commands you do this with. Then in your script, just add sudo before every iwconfig and it should work.

As for waiting, the command is sleep followed by the number of seconds you want to wait. So sleep 10 would wait for 10 seconds before executing the next command.

However, I'm afraid I can't help you with checking the MAC address. I can do it in perl, but I have no idea how to do it with a shell script.
 
Old 11-17-2004, 02:03 AM   #3
andy7t
Member
 
Registered: Oct 2004
Posts: 43

Original Poster
Rep: Reputation: 15
Perl

Thanks for the sudo information.

I can write perl myself (not that well), so would you just use a regex to check it?
 
Old 11-17-2004, 08:16 AM   #4
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 420Reputation: 420Reputation: 420Reputation: 420Reputation: 420
Re: Perl

Quote:
Originally posted by andy7t
Thanks for the sudo information.

I can write perl myself (not that well), so would you just use a regex to check it?
That is how I would approach it. I think bash can do something similar, I'm just not familiar with how.
 
  


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
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 03:53 AM
How to call a script from a system startup script? jonatito Linux - Newbie 7 11-11-2005 10:40 PM
wi-fi startup script Nodren Linux - Wireless Networking 6 05-09-2005 09:56 AM
network startup script for redhat 9 durden2.0 Linux - Newbie 2 04-12-2004 08:17 PM
What's a startup script? rdaves@earthlink.net Linux - Newbie 1 05-22-2001 04:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking > Linux - Wireless Networking

All times are GMT -5. The time now is 05:12 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration