简体   繁体   English

从shell输出中提取特定字符

[英]Extract a specific character from shell output

When I execute: 当我执行时:

root@imx6slzbha:~# iw wlan0 scan

I receive the following as output, it gives me multiple nearby SSID data. 我收到以下输出信息,它为我提供了附近的多个SSID数据。

How can I fetch Signal strength based on a specific SSID Name? 如何根据特定的SSID名称获取信号强度?

Currently, I am fetching based on BSS using this command: 目前,我正在使用以下命令基于BSS进行获取:

iw wlan0 scan | sed -n '/bc:d1:1f:16:55:c7/,/WMM/p' | grep signal | sed 's/.*-//' | awk '{print $1}' | cut -d . -f 1

But I may not know the BSS each time so need a generic answer to this requirement. 但是我可能并不每次都知道BSS,因此需要对此要求有一个通用的答案。 enter image description here 在此处输入图片说明

BSS c8:00:84:85:41:b1 (on wlan0)
        TSF: 4138861160471 usec (47d, 21:41:01)
        freq: 2462
        beacon interval: 102
        capability: ESS ShortPreamble ShortSlotTime (0x1421)
        signal: -80.00 dBm
        last seen: 90 ms ago
        SSID: Swarovski_Guest
        Supported rates: 1.0* 2.0* 5.5* 6.0 9.0 11.0* 12.0 18.0
        DS Parameter set: channel 11
        Country: IN     Environment: Indoor/Outdoor
                Channels [1 - 11] @ 30 dBm
        ERP: <no flags>
        HT capabilities:
                Capabilities: 0x19ac
                        HT20
                        SM Power Save disabled
                        RX HT20 SGI
                        TX STBC
                        RX STBC 1-stream
                        Max AMSDU length: 7935 bytes
                        DSSS/CCK HT40
                Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
                Minimum RX AMPDU time spacing: 8 usec (0x06)
                HT RX MCS rate indexes supported: 0-23
                HT TX MCS rate indexes are undefined
        Extended supported rates: 24.0 36.0 48.0 54.0
        HT operation:
                 * primary channel: 11
                 * secondary channel offset: no secondary
                 * STA channel width: 20 MHz
                 * RIFS: 0
                 * HT protection: nonmember
                 * non-GF present: 1
                 * OBSS non-GF present: 0
                 * dual beacon: 0
                 * dual CTS protection: 0
                 * STBC beacon: 0
                 * L-SIG TXOP Prot: 0
                 * PCO active: 0
                 * PCO phase: 0
        Extended capabilities: 4, 6
        WMM:     * Parameter version 1
                 * u-APSD
                 * BE: CW 15-1023, AIFSN 3
                 * BK: CW 15-1023, AIFSN 7
                 * VI: CW 7-15, AIFSN 2, TXOP 3008 usec
                 * VO: acm CW 3-7, AIFSN 2, TXOP 1504 usec
BSS a0:ab:1b:cf:28:ae (on wlan0)
        TSF: 3196211626 usec (0d, 00:53:16)
        freq: 2462
        beacon interval: 100
        capability: ESS Privacy ShortPreamble ShortSlotTime (0x0431)
        signal: -74.00 dBm
        last seen: 80 ms ago
        Information elements from Probe Response frame:
        SSID: FOTA_Rashmi_2.4G
        Supported rates: 1.0* 2.0* 5.5* 11.0* 9.0 18.0 36.0 54.0
        DS Parameter set: channel 11
        Extended supported rates: 6.0 12.0 24.0 48.0
        Country: EU     Environment: Indoor/Outdoor
                Channels [1 - 13] @ 20 dBm
        TIM: DTIM Count 0 DTIM Period 1 Bitmap Control 0x0 Bitmap[0] 0x2
        WPS:     * Version: 1.0
                 * Wi-Fi Protected Setup State: 2 (Configured)
                 * UUID: 28802880-2880-1880-a880-a0ab1bcf28ae
                 * RF Bands: 0x1
                 * Unknown TLV (0x1049, 6 bytes): 00 37 2a 00 01 20
        ERP: <no flags>
        HT capabilities:
                Capabilities: 0x11ee
                        HT20/HT40
                        SM Power Save disabled
                        RX HT20 SGI
                        RX HT40 SGI
                        TX STBC
                        RX STBC 1-stream
                        Max AMSDU length: 3839 bytes
                        DSSS/CCK HT40
                Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
                Minimum RX AMPDU time spacing: 4 usec (0x05)
                HT RX MCS rate indexes supported: 0-15, 32
                HT TX MCS rate indexes are undefined
        HT operation:
                 * primary channel: 11
                 * secondary channel offset: no secondary
                 * STA channel width: 20 MHz
                 * RIFS: 0
                 * HT protection: nonmember
                 * non-GF present: 0
                 * OBSS non-GF present: 0
                 * dual beacon: 0
                 * dual CTS protection: 0
                 * STBC beacon: 0
                 * L-SIG TXOP Prot: 0
                 * PCO active: 0
                 * PCO phase: 0
        Extended capabilities: HT Information Exchange Supported
        WPA:     * Version: 1
                 * Group cipher: TKIP
                 * Pairwise ciphers: TKIP CCMP
                 * Authentication suites: PSK
        RSN:     * Version: 1
                 * Group cipher: TKIP
                 * Pairwise ciphers: TKIP CCMP
                 * Authentication suites: PSK
                 * Capabilities: (0x0000)
        WMM:     * Parameter version 1
                 * BE: CW 15-1023, AIFSN 3
                 * BK: CW 15-1023, AIFSN 7
                 * VI: CW 7-15, AIFSN 2, TXOP 3008 usec
                 * VO: CW 3-7, AIFSN 2, TXOP 1504 usec

In order use a given SSID, eg "Swarovski_Guest" you can: 为了使用给定的SSID,例如“ Swarovski_Guest”,您可以:

sed -n '/signal/h;/SSID: Swarovski_Guest/{x;s/^.*: -\(.*\) dBm$/\1/;p}'
  • look for signal strength /signal/ 寻找信号强度/signal/
  • store it in history h; 将其存储在历史记录h;
  • look for specific SSID name /SSID: Swarovski_Guest/ 查找特定的SSID名称/SSID: Swarovski_Guest/
  • retrieve the signal strength x; 检索信号强度x;
  • trim anything but the value number s/^.*: -\\(.*\\) dBm$/\\1/; 修剪值s/^.*: -\\(.*\\) dBm$/\\1/;任何内容s/^.*: -\\(.*\\) dBm$/\\1/;
  • print it p 打印p

Output for sample input: 样本输入的输出:

 80.00

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM