8

I'm able to get the signal strength of all Wi-Fi networks with the following command:

$ nmcli -t -f SIGNAL device wifi list
$ 77
  67
  60
  59
  55
  45
  44
  39
  39
  37

I would like to reduce this list only to the current Wi-Fi on which I'm connected. I've been through the man page but can't find the necessary flag.

One solution would be to use sed or awk, but I would like to avoid piping.

Should I use nmcli device wifi instead of parsing directly for the SIGNAL column?

Grégoire Borel
  • 183
  • 1
  • 1
  • 4

4 Answers4

6
nmcli --version
nmcli tool, version 1.6.2

To get the SIGNAL of the AP on which you are connected, use:

nmcli dev wifi list | awk '/\*/{if (NR!=1) {print $7}}'

The second * mark in nmcli dev wifi list is set to identify the SSID on which your are connected.

nmcli --version
nmcli tool, version 1.22.10

use:

nmcli dev wifi list | awk '/\*/{if (NR!=1) {print $6}}'
GAD3R
  • 63,407
  • 31
  • 131
  • 192
6

The trick here is to use the -f parameter of nmcli to specify what fields you want in your script. If you care about the SSID, use the SSID field; if you care about which one you're connected to, use the IN-USE field:

$ nmcli -f IN-USE,SIGNAL device wifi
*  SIGNAL 
   90
*  73     
   40
$ nmcli -f IN-USE,SIGNAL,SSID device wifi
*  SIGNAL  SSID               
   90      wifiWithoutSpaces
*  73      Some Wifi With Spaces
   40      Wifi With a * in its SSID

The advantage of ordering the fields in this way is that selecting the signal is a fixed number of column-delimiting characters from the start of the row; we can now use GAD3R's answer without running into column count or nmcli versioning issues:

$ nmcli -f IN-USE,SIGNAL,SSID device wifi | awk '/^\*/{if (NR!=1) {print $2}}'
73
apnorton
  • 161
  • 1
  • 4
2

If you know the name of the network you're connected to, you could modify your approach like this: (for nmcli 1.14.6, other versions may vary)

nmcli -t -f SSID,SIGNAL dev wifi list | grep "^<network name>:" | cut -d : -f 2
telcoM
  • 87,318
  • 3
  • 112
  • 232
0

A simple way to see the router in use:

nmcli -f IN-USE,SIGNAL device wifi | grep '*'
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Pasi
  • 1