LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

Rep: Reputation: 38
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:
Code:
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, 06:51 PM   #2
wget
LQ Newbie
 
Registered: Apr 2008
Distribution: Slackware 12.0 Kernel 2.6.25, LFS 2.6.25.1 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.

Code:
#!/bin/bash
IFS='"'
essid=`iwlist wlan0 scan | grep ESSID | cut  -f2 -d: `

declare -a essidArray

index=0

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

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

             essidArray[${index}]=$j
             echo $index" "$j
             index=$(( $index + 1 ))
        fi
done

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

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

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

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


Reply

Tags
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 10:54 PM
Xandros and wireless networks newbiesforever LinuxQuestions.org Member Success Stories 3 05-27-2006 07:51 AM
help need regarding wireless networks vesky70 Linux - Laptop and Netbook 1 01-31-2006 11:18 AM
issues with mirc script accessing our php script dtra Linux - Software 2 07-02-2005 04:30 PM
wireless networks gui10 Linux - Wireless Networking 10 05-27-2002 04:42 PM


All times are GMT -5. The time now is 06:44 PM.

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