Grepping iwinfo

Hi fellow members
I'm looking at using the iwinfo package to capture (to file) signal strengths of connected users in my house, so I can later examine them (clients), as they move round my house-it will help to find out the dead spots-and be interesting at the same time.My problem is iwinfo returns the info over multiple lines for each station

root@TP-Loft:~# iwinfo wlan0 assoclist;iwinfo wlan0-1 assoclist;iwinfo wlan0-2 assoc
No station connected
No station connected
A0:56:F3:50:xx:xx  -53 dBm / -95 dBm (SNR 42)  90 ms ago
        RX: 144.4 MBit/s, MCS 15, 20MHz                21677 Pkts.
        TX: 130.0 MBit/s, MCS 15, 20MHz                11999 Pkts.

I'd like to know if there is a way to capture the info, and then manipulate it before being saved to file (bash script?) onto just one line per client?-so:

A0:56:F3:50:xx:xx  -53 dBm / -95 dBm (SNR 42)  90 ms ago RX: 144.4 MBit/s, MCS 15, 20MHz TX: 130.0 MBit/s, MCS 15, 20MHz 11999 Pkts 21677 Pkts

sort of idea (with maybe a date time stamp thrown in for good measure :slight_smile: ? Can anybody help?

Thanks
cabs

You can do grep -A2 to capture two lines after mac address match or you can save the SNR info only and analyze that.

Thanks for the reply-yes, getting the first line is easy but I'd like to get the MCS value on the 2nd and 3rd lines as well

grep -A2 just seems to return an error?

root@TP-Loft:~# iwinfo wlan1 assoclist
A4:2B:B0:A5:xx:xx  -63 dBm / -90 dBm (SNR 27)  0 ms ago
        RX: 216.0 MBit/s, MCS 13, 40MHz              1697790 Pkts.
        TX: 216.0 MBit/s, MCS 13, 40MHz               204762 Pkts.

root@TP-Loft:~# iwinfo wlan1 assoclist | grep -A 2

I'll continue to see what I'm doing wrong!

Cheers
cabs

Just use the right tool ... :slight_smile: here a working example in awk:

iwinfo wlan0 assoclist | awk '/^[[:alnum:]]/{printf $0;for(line=1;line<=3;line++){getline;printf(line==3)?$0"\n":$0}}'

Output:

xx:xx:xx:xx:xx:xx  -61 dBm / -102 dBm (SNR 41)  10 ms ago	RX: 400.0 MBit/s, VHT-MCS 9, 40MHz, VHT-NSS 2     22810 Pkts.	TX: 180.0 MBit/s, VHT-MCS 8, 40MHz, VHT-NSS 1     15077 Pkts.	expected throughput: unknown
xx:xx:xx:xx:xx:xx  -51 dBm / -102 dBm (SNR 51)  0 ms ago	RX: 200.0 MBit/s, VHT-MCS 9, 40MHz, VHT-NSS 1     44616 Pkts.	TX: 180.0 MBit/s, VHT-MCS 8, 40MHz, VHT-NSS 1     63417 Pkts.	expected throughput: unknown

2 Likes

You need to grep something to get two lines after match. I assumed you were grepping a mac address.

Or use Dirk's awk solution.

Apologies, I was away on vacation-many thanks for the replies-will have a go with them all this week.

Thanks
cabs

Happy New Year all!
On vacation (again) so having a play with this again-is there a way to get the date/time appended to each line, rather than as a summary above each of the client?

Current command:

while true; do date ; iwinfo wlan0-1 assoclist | awk '/^[[:alnum:]]/{printf $0;for(line=1;line<=3;line++){getline;printf(line==3)?$0"\n":$0}}' ; sleep 2; done
Wed Jan  1 15:28:57 UTC 2020  
F8:1A:67:5A:DE:C4  -78 dBm / -103 dBm (SNR 25)  120 ms ago      RX: 81.0 MBit/s, MCS 4, 40MHz                 461071 Pkts.      TX: 6.0 MBit/s                                355517 Pkts.  
E8:F2:E2:67:B9:F8  -67 dBm / -103 dBm (SNR 36)  50 ms ago       RX: 24.0 MBit/s                               951552 Pkts.      TX: 6.0 MBit/s                               5355256 Pkts.  
Wed Jan  1 15:29:07 UTC 2020  
F8:1A:67:5A:DE:C4  -78 dBm / -103 dBm (SNR 25)  860 ms ago      RX: 81.0 MBit/s, MCS 4, 40MHz                 461202 Pkts.      TX: 6.0 MBit/s                                355632 Pkts.  
E8:F2:E2:67:B9:F8  -67 dBm / -103 dBm (SNR 36)  230 ms ago      RX: 24.0 MBit/s                               951844 Pkts.      TX: 6.0 MBit/s                               5355581 Pkts.  
Wed Jan  1 15:29:17 UTC 2020  
F8:1A:67:5A:DE:C4  -79 dBm / -103 dBm (SNR 24)  880 ms ago      RX: 81.0 MBit/s, MCS 10, 40MHz                461242 Pkts.      TX: 6.0 MBit/s                                355650 Pkts.  
E8:F2:E2:67:B9:F8  -67 dBm / -103 dBm (SNR 36)  70 ms ago       RX: 24.0 MBit/s                               951969 Pkts.      TX: 6.0 MBit/s                               5355606 Pkts.  
root@LEDE:~#

Just assign the current date to a variable in awk and use this variable in the printf output, e.g.:

iwinfo wlan0 assoclist | awk -v date="$(date "+%d.%m.%Y %H:%M:%S")" '/^[[:alnum:]]/{printf "%s ::: %s",date,$0;for(line=1;line<=3;line++){getline;printf(line==3)?$0"\n":$0}}'

Output:

01.01.2020 19:53:25 ::: AA:BB:CC:DD:EE:FF  -69 dBm / unknown (SNR -69)  0 ms ago	RX: 108.0 MBit/s                               19581 Pkts.	TX: 121.5 MBit/s                               39076 Pkts.	expected throughput: unknown

Edit: Happy New Year! :slightly_smiling_face:

1 Like

Many thanks Sir-that works a treat!

Cabs

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.