Get connected Wi-Fi network signal strength with nmcli
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.6.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
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