Linux 如何将脚本从iwconfig升级到iw?

Linux 如何将脚本从iwconfig升级到iw?,linux,shell,fish,Linux,Shell,Fish,我使用此脚本打印一个格式化字符串,表示我的实际wifi连接及其强度: #! /run/current-system/sw/bin/nix-shell #! nix-shell -i fish -p fish set active (ip addr | awk '/state UP/ {print $2}' | sed 's/.$//' | head -n 1) if test -n $active set essid (iwconfig $active | awk -F '"

我使用此脚本打印一个格式化字符串,表示我的实际wifi连接及其强度:

#! /run/current-system/sw/bin/nix-shell
#! nix-shell -i fish -p fish

set active (ip addr | awk '/state UP/ {print $2}' | sed 's/.$//' | head -n 1)

if test -n $active
    set essid (iwconfig $active | awk -F '"' '/ESSID/ {print $2}')
    set strength (iwconfig $active | awk -F '=' '/Quality/ {print $2}' | cut -d '/' -f 1)
    set bars (expr $strength / 10)
else
    echo "No device up"
    exit 1
end

switch $bars
    case 0
        set bars "[----------]"
    case 1
        set bars "[/---------]"
    case 2
        set bars "[//--------]"
    case 3
        set bars "[///-------]"
    case 4
        set bars "[////------]"
    case 5
        set bars "[/////-----]"
    case 6
        set bars "[//////----]"
    case 7
        set bars "[///////---]"
    case 8
        set bars "[////////--]"
    case 9
        set bars "[/////////-]"
    case 10
        set bars "[//////////]"
    case "*"
        set bars "[----!!----]"
end

echo $essid $bars
它工作正常,但是我将Linux发行版更改为
NixOS
,其中
iw*
命令已被弃用,因此我们只有
iw
命令

在我的搜索中,我发现了这个命令:
iw station dump
,它向我显示了很多信息,但现在正是我所需要的

它不显示我的实际
AP
,信号ios显示为带负数的dBm

如何将旧的
iwconfig
命令升级到
iw
?有可能吗?

基于此,我们有以下几点:

cfg80211 wext兼容层假设信号范围为-110 dBm至-40 dBm,质量值通过将110添加到信号电平得出

因此,请记住以下内容(基于iw命令的样例输出):

将给您一个最大值为10的值,但您几乎永远不会得到10,因为它将向下取整。如果要将其四舍五入为9.6之类的值,请在乘以(例如)之前将该值加上0.5

$ set dbstrength -41
$ math -s0 \( 110 + $dbstrength \) \* 10 / 70
9
$ math -s0 \( \( 110 + $dbstrength + 0.5 \) \* 10 \) + 0.5
10
基于此,我们得出以下结论:

cfg80211 wext兼容层假设信号范围为-110 dBm至-40 dBm,质量值通过将110添加到信号电平得出

因此,请记住以下内容(基于iw命令的样例输出):

将给您一个最大值为10的值,但您几乎永远不会得到10,因为它将向下取整。如果要将其四舍五入为9.6之类的值,请在乘以(例如)之前将该值加上0.5

$ set dbstrength -41
$ math -s0 \( 110 + $dbstrength \) \* 10 / 70
9
$ math -s0 \( \( 110 + $dbstrength + 0.5 \) \* 10 \) + 0.5
10

这更有道理。我不知道
iw-dev-link
!这就解决了我的问题。你能为
SSID
添加解决方案吗?我的答案是:
set-essid(iw-dev$activelink | awk'$1~/SSID/{$1=”“;print$0}')
,这更有意义。我不知道
iw-dev-link
!这就解决了我的问题。你能为
SSID
添加解决方案吗?我的答案是:
set-essid(iw-dev$activelink | awk'$1~/SSID/{$1=”“;print$0})