LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 07-08-2009, 05:43 AM   #1
Chris_no
LQ Newbie
 
Registered: Jun 2009
Distribution: Ubuntu 8.04 Hardy Heron
Posts: 15

Rep: Reputation: 0
Sorting content of iwlist scan.


Hi.

I'm currently learning myself bash scripting.

I've run into a problem that I can see no easy solution to.

This is the script.
I've commented out the lines that are not working.

Code:
#!/bin/bash

flag=1
count=$(iwlist scan 2>/dev/null | grep Cell | wc -l)
(( count++ ))

while [ $flag -lt $count ]; do

cell=$(iwlist scan 2>/dev/null | grep "Cell 0$flag")
#essid=$(iwlist scan 2>/dev/null | grep ESSID ) #WHAT TO USE???


echo -n "$cell --- "
#echo "$essid"
echo ""

(( flag++ ))

done

exit 0
What I like to do is make the "ESSID" line appear behind the "Cell" line, but there are no uniqe way to identify this to grep.

Is there any other tool that can do this or just exract the collected info from the $essid variable?

Any advise to simplify my script even further is appeciated.

PS: I know that your favourite language probably beats shellscripting, but I'm not trying to learn that language right now.

Last edited by Chris_no; 07-08-2009 at 06:01 AM.
 
Old 07-08-2009, 06:59 AM   #2
Chris_no
LQ Newbie
 
Registered: Jun 2009
Distribution: Ubuntu 8.04 Hardy Heron
Posts: 15

Original Poster
Rep: Reputation: 0
This is the solution!

Ah fixed the problem.

Code:
#!/bin/bash

flag=1
count=$(iwlist scan 2>/dev/null | grep Cell | wc -l)
iwlist scan 2>/dev/null | grep ESSID > buffer.cr

(( count++ ))

while [ $flag -lt $count ]; do

cell=$(iwlist scan 2>/dev/null | grep "Cell 0$flag")
essid=$(sed -n -e "${flag}p" ./buffer.cr)

echo -n "$cell"
echo "$essid"
echo ""

(( flag++ ))

done

exit 0
 
Old 07-08-2009, 10:13 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
And a little off-topic note on the side (learning English as well as bash! ;}):

It's "teaching myself bash scripting" or "learning bash scripting".


Cheers,
Tink
 
Old 07-09-2009, 11:52 AM   #4
Chris_no
LQ Newbie
 
Registered: Jun 2009
Distribution: Ubuntu 8.04 Hardy Heron
Posts: 15

Original Poster
Rep: Reputation: 0
NIce to know.

That is nice to know.

In Norwegian to learn and to teach is almost the same word.
We say "lære"="learn" and "lære (bort)"="teach (away)".

To teach (away) to yourself is a new concept for me. :-)
 
Old 07-09-2009, 12:43 PM   #5
Chris_no
LQ Newbie
 
Registered: Jun 2009
Distribution: Ubuntu 8.04 Hardy Heron
Posts: 15

Original Poster
Rep: Reputation: 0
The finished script.

I'll add the finished script commented and a bit fancier if anybody need it.

Code:
#!/bin/bash

#We define a loopcontrol flag and programpath
flag=1
path1="/home/chris/run/"
#We count the number of networks visible
count=$(iwlist scan 2>/dev/null | grep Cell | wc -l)

#We put the essid info in a temp-file before the loop
#since we only need it once.
iwlist scan 2>/dev/null | grep ESSID > buffer.cr

#Our loop checks the increasing value of flag agaisnt number of networks
until [ $flag -gt $count ]; do
	
	#We find the mac address of the networks one at a time and fixes the presentation
	cell=$(iwlist scan 2>/dev/null | grep "Cell 0$flag" | sed 's/Cell//')
	#We extract the network names from the temp-file one at a time
	essid=$(sed -n -e "$flag p" ./buffer.cr)

	echo $cell "---" $essid #Prints the netaddressinfo on screen

	(( flag++ )) #Adding to the flag so we know how far we have come in the loop

done | tee ${path1}nett.txt #We are done so we put the result in a file for later use

#In case root run this we don't want to be locked out
chown chris ${path1}nett.txt
#Deleting the temporary file buffer.cr
rm ./buffer.cr

exit 0
If you know any better way to do this let me know.
 
  


Reply



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
iwlist scan - no scan results compu73rg33k Linux - Wireless Networking 6 05-29-2009 02:37 AM
Iwlist scan y00b Linux - Wireless Networking 17 11-15-2006 08:38 PM
iwlist scan not supported mcd Linux - Wireless Networking 14 02-09-2006 07:42 PM
cannot see any AP using iwlist wlan0 scan dpowers Linux - Wireless Networking 5 08-28-2005 09:36 AM
iwlist and active scan hjd17 Linux - Software 1 04-12-2005 09:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:17 AM.

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
Open Source Consulting | Domain Registration