ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Slackware 14 (Server),OpenSuse 13.2 (Laptop & Desktop),, OpenSuse 13.2 on the wifes lappy
Posts: 781
Rep:
grepping unknown text, is there a way?
As the title says, I need to grep some unknown text in order to pass that text as an argument to another app.
The text I need to grep will appear in a text file as a result of interrogating app1, and directing the output to a text file, where I would like it to be automatically extracted and passed to app2.
Now I know that I could then read the text file produced, and manually pass the info I need to app2, but I can imagine a case where it ought to be possible to do that automatically.
So, is there any way of doing this, or would some other way need to be found?
By the way, that takes everything written by stdout from app1 and pipes it to grep's stdin, and then takes grep's stdout and pipes it to app2's stdin. So if app2 accepts input on stdin then that works fine. There are also other ways, for example:
Code:
app2 -someoption `app1 | grep blah`
That will take the output of app1, grep for blah, and pass the output of grep as command line arguments to app2 just after the -someoption command line param.
Distribution: Slackware 14 (Server),OpenSuse 13.2 (Laptop & Desktop),, OpenSuse 13.2 on the wifes lappy
Posts: 781
Original Poster
Rep:
Maybe a better explanation as to what I am trying to achieve. It all revolves around not being able to find any sort of working utility that automatically searches for, then logs me into a wireless hot spot. I have tried the kde wireless utility, it just doesn't work automatically, Network Manager is just to unstable, and has to many dependencies, and wap_supplicant seems to be a case of using a large hammer to crack a peanut, so I am looking for something much simpler by way of a shell script.
I see the problem like this:-
1) Scan for a wireless AP using iwlist wlano scan >wirelessscanresults.txt
2) Extract the essid (if any) from the .txt file and pass it as a parameter to iwconfig, i.e. iwconfig wlan0 essid "extracted text"
3) Check in the .txt file if the AP needs a key, or not.
4) If it does, then prompt for the key, and pass to iwconfig as an argument. If not, then bring up the interface with ifconfig
5) If no scan results are found at all, then print some sort of message to screen informing the user, i.e. me, that no wireless network is available.
So you can now see the problem, to automate the process, the results of the scan, which will be unknown, and variable need to be extracted and used by iwconfig to set up the wireless network card.
Any more suggestions, as I don't think what you have currently proposed is exactly what I am looking for.
Distribution: Slackware 14 (Server),OpenSuse 13.2 (Laptop & Desktop),, OpenSuse 13.2 on the wifes lappy
Posts: 781
Original Poster
Rep:
bigearsbilly, or should that be bigheadbilly
It may be almost to simple for you, and if it is, how about some help here. I have done absolutely zero scripting with Linux to date, so this will be my first attempt at anything of this type, so a little latitude, and less attitude would be helpfull.
jlliagre, no I haven't coded anything yet. I have a fairly good idea how I want to start for myself, and then hopefully expand on it later, but for now I need to find out how to strip out the essid and key info in step 2.
Distribution: Slackware 14 (Server),OpenSuse 13.2 (Laptop & Desktop),, OpenSuse 13.2 on the wifes lappy
Posts: 781
Original Poster
Rep:
Hi bigearsbilly,
And my apologies for jumping down your throat, just having a bad day I guess.
Anyway, below is the output from iwlist:-
wlan0 Scan completed :
Cell 01 - Address: 00:30:BD:FB:E4:70
ESSID:"adanddad"
Protocol:IEEE 802.11b
Mode:Managed
Frequency:2.462 GHz (Channel 11)
Quality:0/100 Signal level:-45 dBm Noise level:-256 dBm
Encryption keyn
Bit Rate:1 Mb/s
Bit Rate:2 Mb/s
Bit Rate:5.5 Mb/s
Bit Rate:11 Mb/s
Bit Rate:18 Mb/s
Bit Rate:24 Mb/s
Bit Rate:36 Mb/s
Bit Rate:54 Mb/s
Bit Rate:6 Mb/s
Bit Rate:9 Mb/s
Bit Rate:12 Mb/s
Bit Rate:48 Mb/s
Extra:bcn_int=100
Extra:atim=0
Cell 02 - Address: 03:00:B2:FF:24:BB
ESSID:"TimsOffice"
Protocol:IEEE 802.11b
Mode:Managed
Frequency:2.462 GHz (Channel 6)
Quality:0/100 Signal level:-65 dBm Noise level:-184 dBm
Encryption keyn
Bit Rate:1 Mb/s
Bit Rate:2 Mb/s
Bit Rate:5.5 Mb/s
Bit Rate:11 Mb/s
Bit Rate:18 Mb/s
Bit Rate:24 Mb/s
Bit Rate:36 Mb/s
Bit Rate:54 Mb/s
Bit Rate:6 Mb/s
Bit Rate:9 Mb/s
Bit Rate:12 Mb/s
Bit Rate:48 Mb/s
Extra:bcn_int=100
Extra:atim=0
Cell 01 - Address: D3:0D:11:30:01:6F
ESSID:"YouNeedSecurity"
Protocol:IEEE 802.11b
Mode:Managed
Frequency:2.462 GHz (Channel 9)
Quality:0/100 Signal level:-72 dBm Noise level:-142 dBm
Encryption keyff
Bit Rate:1 Mb/s
Bit Rate:2 Mb/s
Bit Rate:5.5 Mb/s
Bit Rate:11 Mb/s
Bit Rate:18 Mb/s
Bit Rate:24 Mb/s
Bit Rate:36 Mb/s
Bit Rate:54 Mb/s
Bit Rate:6 Mb/s
Bit Rate:9 Mb/s
Bit Rate:12 Mb/s
Bit Rate:48 Mb/s
Extra:bcn_int=100
Extra:atim=0
As you can see, I am scanning three wireless APs, two are encrypted, as shown by the Encryption keyn line, whilst the third is not. Now I can of course send this output to a text file, then read that file to find out the names of the scannes APs, and whether they are encrypted or not, then use that as a modifier to the iwconfig command. What I would lke to do of course, is to automate that process. The problem is, as I move around the country a lot, the ESSID will be different whenever I am lucky enough to find wireless points, and manually setting up my wireless card gets a bit tiring. In fact, it sometimes tempts me to use Micro$haft XP as it can do what I want. So I reckon it must be possible under my favourite OS as well, I just don't know how to go about extracting the info I need, when I don't know the info in the first place!
So, any suggestions?
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
This looks like something that can easily be solved with awk.
The iwlist output is made of clearly identifiable records with a colon delimiter, just extract the ESSID, encryption key status from each one, and you are almost done.
Here's a messy graphical start:
relies on you doing
Quote:
1) Scan for a wireless AP using iwlist wlano scan >wirelessscanresults.txt
i've hard-coded the data file for the moment.
assuming you have tcl/tk using the data in earlier post
Code:
#!/bin/sh
#\
exec wish "$0" "$@"
set fp [ open "| /usr/bin/cat ./wirelessscanresults.txt" ]
# set fp [ open "| /sbin/iwlist wlano scan" ] ### try uncommenting this if it works
gets $fp ; # skip first line
set f1 [frame .f1 -borderwidth 3]
set f2 [frame .f2 -borderwidth 3]
set f2 [frame .f3 -borderwidth 3]
set scroll .f1.scroll
set cells .f1.cells
set quit [button .f2.quit -command exit -text "Quit"]
set cells[listbox .f1.cells -yscrollcommand "$scroll set"]
set scroll [scrollbar $scroll -command ".f1.cells yview" ]
$cells configure -yscrollcommand "$scroll set"
bind $cells <ButtonRelease-1> { list_network }
pack .f1 .f3 .f2 -side top
pack $cells $scroll -side left -fill y
pack $quit -side bottom
set count -1
proc list_network {} {
upvar networks networks
set index [selection get]
set count 0
if {[info exists networks($index)] < 0} {return}
destroy .f3.sub
pack [frame .f3.sub]
#pack [ label .f3.win ] -side left
foreach thing $networks($index) {
puts $thing
pack [ label .f3.sub.$count -text $thing] -side top
incr count
}
}
while { [gets $fp line] >= 0 } {
if { [string match *Cell* $line ] } {
set count $line
set L [split $line ]
$cells insert end $line
set networks($count)[list $line]
puts -nonewline "\n$count)";
} else {
lappend networks($count) $line
}
}
$cells selection set 0 0
foreach nm [array names networks] {
puts "$nm = $networks($nm)"
}
list_network
./wirelessscanresults.txt
Code:
wlan0 Scan completed :
Cell 01 - Address: 00:30:BD:FB:E4:70
ESSID:"adanddad"
Protocol:IEEE 802.11b
Mode:Managed
Frequency:2.462 GHz (Channel 11)
Quality:0/100 Signal level:-45 dBm Noise level:-256 dBm
Encryption key:on
Bit Rate:1 Mb/s
Bit Rate:2 Mb/s
Bit Rate:5.5 Mb/s
Bit Rate:11 Mb/s
Bit Rate:18 Mb/s
Bit Rate:24 Mb/s
Bit Rate:36 Mb/s
Bit Rate:54 Mb/s
Bit Rate:6 Mb/s
Bit Rate:9 Mb/s
Bit Rate:12 Mb/s
Bit Rate:48 Mb/s
Extra:bcn_int=100
Extra:atim=0
Cell 02 - Address: 03:00:B2:FF:24:BB
ESSID:"TimsOffice"
Protocol:IEEE 802.11b
Mode:Managed
Frequency:2.462 GHz (Channel 6)
Quality:0/100 Signal level:-65 dBm Noise level:-184 dBm
Encryption key:on
Bit Rate:1 Mb/s
Bit Rate:2 Mb/s
Bit Rate:5.5 Mb/s
Bit Rate:11 Mb/s
Bit Rate:18 Mb/s
Bit Rate:24 Mb/s
Bit Rate:36 Mb/s
Bit Rate:54 Mb/s
Bit Rate:6 Mb/s
Bit Rate:9 Mb/s
Bit Rate:12 Mb/s
Bit Rate:48 Mb/s
Extra:bcn_int=100
Extra:atim=0
Cell 01 - Address: D3:0D:11:30:01:6F
ESSID:"YouNeedSecurity"
Protocol:IEEE 802.11b
Mode:Managed
Frequency:2.462 GHz (Channel 9)
Quality:0/100 Signal level:-72 dBm Noise level:-142 dBm
Encryption key:off
Bit Rate:1 Mb/s
Bit Rate:2 Mb/s
Bit Rate:5.5 Mb/s
Bit Rate:11 Mb/s
Bit Rate:18 Mb/s
Bit Rate:24 Mb/s
Bit Rate:36 Mb/s
Bit Rate:54 Mb/s
Bit Rate:6 Mb/s
Bit Rate:9 Mb/s
Bit Rate:12 Mb/s
Bit Rate:48 Mb/s
Extra:bcn_int=100
Extra:atim=0
Distribution: Slackware 14 (Server),OpenSuse 13.2 (Laptop & Desktop),, OpenSuse 13.2 on the wifes lappy
Posts: 781
Original Poster
Rep:
Well it looks like I'm gonna have to go and learn AWK and/or Perl, (or maybe both), so I'll be back here when I've done that. Don't know how long thats gonna take, and at my age it could be a while. Thanks for all your input so far both, but it looks a bit out of my knowledge stream at the moment. One day maybe!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.