LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   help bash scripting (https://www.linuxquestions.org/questions/linux-newbie-8/help-bash-scripting-353292/)

sh4d0w13 08-14-2005 09:14 PM

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!

Matir 08-14-2005 10:46 PM

Try adding in "iwconfig eth1" after your iwconfig statements to see if it associated.

bigrigdriver 08-14-2005 11:02 PM

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'

Matir 08-14-2005 11:10 PM

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.

Emmanuel_uk 08-15-2005 02:55 AM

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

heema 08-15-2005 03:02 AM

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

#!/bin/bash -x


All times are GMT -5. The time now is 11:16 PM.