Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-22-2008, 02:57 PM   #1
Registered: Feb 2004
Location: Valby, Denmark / Citizen of the Web
Distribution: Slackware 14.1
Posts: 879

Rep: Reputation: 39
Question Script for accessing wireless networks

Dear all,
I am a... in flattering terms: Novice in scripting.
I have been playing with making a script for accessing a wireless network.
I am getting a list of the individual networks by calling:
iwlist ath0 scanning | grep ESSID | cut -d '"' -f 2
What I would like to do is to pull out the individual lines:
1: Network 1
2: Network 2
- and then having a prompt: Which network would I like to connect to, and then passing the name string to dhcpcd.
Making that work, I would like to filter the empty lines. Some of the networks report presence, but not a name. It is safe to ignore these.
Would anyone be able to help me with this? I am not sure how to split to the individual lines.
Old 08-22-2008, 07:51 PM   #2
LQ Newbie
Registered: Apr 2008
Distribution: Slackware 12.0 Kernel 2.6.25, LFS Kernel
Posts: 25

Rep: Reputation: 15
I gave it a go as I haven't literally used bash myself in years and no doubt it shows! It works, at least in my very limited testing.

essid=`iwlist wlan0 scan | grep ESSID | cut  -f2 -d: `

declare -a essidArray


for i in $essid
        j=`echo $i | sed -e 's/^[ ]*//'`

        if [ ${#j} -gt 0 ]; then

             echo $index" "$j
             index=$(( $index + 1 ))

if [ ${#essidArray[@]} -lt 1 ]; then
        echo "No networks found"
        echo "Select a network number:"
        read networkName

        echo "You selected "${essidArray[$networkName]}

Old 08-23-2008, 03:54 PM   #3
Registered: Feb 2004
Location: Valby, Denmark / Citizen of the Web
Distribution: Slackware 14.1
Posts: 879

Original Poster
Rep: Reputation: 39
Thank you for the script - yes, it works as it should. I will put it to good use - thank you!


bash, network interface

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
accessing computer across networks Madd the Sane Linux - Networking 3 10-26-2007 11:54 PM
Xandros and wireless networks newbiesforever Member Success Stories 3 05-27-2006 08:51 AM
help need regarding wireless networks vesky70 Linux - Laptop and Netbook 1 01-31-2006 12:18 PM
issues with mirc script accessing our php script dtra Linux - Software 2 07-02-2005 05:30 PM
wireless networks gui10 Linux - Wireless Networking 10 05-27-2002 05:42 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:50 AM.

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