我正在尝试编写一个 bash 脚本来轮询 btmon 以获取设备连接。我有一个可行的解决方案,但它慢得离谱,而且问题似乎是 grep 在找到匹配项后退出非常慢(大约 25 秒)。我能做些什么来加速grep
或完全避免使用它?
#!/bin/bash
COUNTER=0
while :
do
until btmon | grep -m 1 '@ Device Connected'
do :
done
let COUNTER=COUNTER+1
echo on 0 | cec-client RPI -s -d 1
sleep 5
echo as | cec-client RPI -s -d 1
until btmon | grep -m 1 '@ Device Disconnected'
do :
done
let COUNTER=COUNTER-1
if [ $COUNTER -eq 0 ];
then echo standby 0 | cec-client RPI -s -d 1;
fi …
Run Code Online (Sandbox Code Playgroud) 通常当我运行时,wpa_supplicant
我会得到一些这样的输出:
Successfully initialized wpa_supplicant
ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
wlan3: Trying to associate with 9c:3d:cf:fb:95:96 (SSID='Bell420' freq=2462 MHz)
wlan3: Association request to the driver failed
wlan3: Associated with 9c:3d:cf:fb:95:96
wlan3: Authentication with 9c:3d:cf:fb:95:96 timed out.
ioctl[SIOCSIWAP]: Operation not permitted
wlan3: CTRL-EVENT-DISCONNECTED bssid=9c:3d:cf:fb:95:96 reason=3 locally_generated=1
wlan3: WPA: 4-Way Handshake failed - pre-shared key may be incorrect
Run Code Online (Sandbox Code Playgroud)
问题是它只是一遍又一遍地尝试。
有没有一种方法可以告诉我wpa_supplicant
在出现明显错误(例如错误的键)时立即退出?
我使用的是带有wpa_supplicant v2.1
.
我写了一个解决方法来监视wpa_supplicant
不正确的密钥。使用grep
上wpa_supplicant
(与stdbuf
基于斯特凡Chazelas'在这里评论 …