nmcli -t -f TYPE,TIMESTAMP,UUID con list |
awk -F\: -v oldts="$(date +%s -d '1 day ago')" '$1 == "802-11-wireless" && $2 < oldts {print $3}' |
while read -r uuid; do
nmcli con delete uuid "$uuid"
done
或(也许更好一点)类似的东西
#!/bin/bash
oldstamp=$(date +%s -d '1 day ago')
while IFS=\: read -r contype timestamp uuid
do
case "$contype" in
802-11-wireless)
if ((timestamp < oldstamp)); then
nmcli con delete uuid "$uuid"
else
echo "$uuid: too new: skipping"
fi
;;
*)
echo "skipping connection type $contype"
;;
esac
done < <(nmcli -t -f TYPE,TIMESTAMP,UUID con list)
对于通过 管理的连接
network-manager
,应该可以通过nmcli
接口执行此操作,例如删除超过 1 天的无线连接或(也许更好一点)类似的东西
权限提升应该由 dbus/policykit 处理,因此
sudo
不需要删除调用用户创建的连接。