LinuxQuestions.org
Register a domain and help support LQ
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 08-14-2005, 09:14 PM   #1
sh4d0w13
Member
 
Registered: Feb 2005
Posts: 74

Rep: Reputation: 15
help bash scripting


I have recently decided to try and write a script that will auto connect me to my wireless by using a bash script, but it has turned out much harder than I initially thought, and I was hoping I could get some help on this:
So far I have got

----------------------------------

#! /bin/bash
iwconfig eth1 essid NETGEAR
iwconfig eth1 key **************
dhclient eth1
exit 0

----------------------------------

but for some reason its not working because it forgets to run dhclient or something I dont know. Thanks!
 
Old 08-14-2005, 10:46 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Try adding in "iwconfig eth1" after your iwconfig statements to see if it associated.
 
Old 08-14-2005, 11:02 PM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,805

Rep: Reputation: 324Reputation: 324Reputation: 324Reputation: 324
Question

I'm not that strong a bash programmer, but I'd suggest that the line "iwconfig eth1 key **************" may be the problem (unless you have some unstated key which is in the program).
Try this instead: immediately before that line, add ' echo "enter the key" | read key' which pauses execution and waits for the user the enter the key, and assigns it to the variable 'key'.
Then edit the next command to read: 'iwconfit eth1 $key'
 
Old 08-14-2005, 11:10 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Quote:
Originally posted by bigrigdriver
I'm not that strong a bash programmer, but I'd suggest that the line "iwconfig eth1 key **************" may be the problem (unless you have some unstated key which is in the program).
Try this instead: immediately before that line, add ' echo "enter the key" | read key' which pauses execution and waits for the user the enter the key, and assigns it to the variable 'key'.
Then edit the next command to read: 'iwconfit eth1 $key'
Code:
echo enter the key | read key
Would a) try to put "enter the key" in key, and b) not work anyway, since $key would only be set in the piped subprocess.
 
Old 08-15-2005, 02:55 AM   #5
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,604

Rep: Reputation: 47
Have you made your bash script executable (just checking, but I think you have)
Does any of these process need to be run as root?
If yes you may need to run the script as root

Beginner as well here

try this (I assume you do not want to type the key everytime and do not care about
having it in plain text in your system

#! /bin/bash
mykey=12345 #enter your key
# mykey="12345ABCD" #enter your key here with double quote this is probably better syntax if you have digits and characters
iwconfig eth1 essid NETGEAR
iwconfig eth1 key $mykey
iwconfig eth1
dhclient eth1
exit 0


There are lots of tutorials out there
This one of my prefered because it is short but quite complete
http://linux-pdf.xs4all.nl/data/alge...20Tutorial.pdf
 
Old 08-15-2005, 03:02 AM   #6
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 46
you could debug the script by adding -x to the line #!/bin/bash

#!/bin/bash -x
 
  


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
Bash scripting pete1234 Programming 1 09-27-2005 02:48 AM
bash scripting.. kurrupt Programming 3 09-21-2005 01:07 AM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 05:09 AM
Bash scripting JonCooperUK Programming 3 03-04-2004 09:55 PM
Bash scripting kbeaver Programming 5 07-18-2003 09:35 PM


All times are GMT -5. The time now is 09:40 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration