gpt4 book ai didi

linux - 使用 udevadm 命令的替代方法

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:24:16 26 4
gpt4 key购买 nike

我有一个脚本,它使用命令 udevadm 获取有关/dev 设备的信息,我的脚本所需的信息是 ID_SERIAL 值,因为我想过滤tty 的 设备代表连接到 USB 端口的特定产品。问题是,环境中存在的 udevm 的 udevadm 版本是 128 而这个版本的 udevadm 没有可用的查询 property .如何以另一种方式过滤连接到 USB 端口的设备?

编辑 1Command.sh

#!/bin/bash

for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev);do
(syspath="${sysdevpath%/dev}";
echo "syspath = $syspath";
devname="$(udevadm info -q name -p $syspath)";
[[ "$devname" == "bus/"* ]]&& continue;
echo "Passou";
eval "$(udevadm info -q property --export -p $syspath)";
[[ -z "$ID_SERIAL" ]] && continue;
temporario=${ID_SERIAL,,};
if [[ $temporario == *"ManufacturerName"* ]];
then
echo "/dev/$devname";
fi);
done;

最佳答案

使用dmesg 的输出不是更容易吗?当我插入我的串口时,我得到这个输出:

[332144.226566] usb 1-2.1.2: new full-speed USB device number 6 using ehci-pci
[332144.302766] usb 1-2.1.2: New USB device found, idVendor=067b, idProduct=2303
[332144.302770] usb 1-2.1.2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[332144.512664] usbcore: registered new interface driver usbserial
[332144.512679] usbcore: registered new interface driver usbserial_generic
[332144.512691] usbserial: USB Serial support registered for generic
[332144.522042] usbcore: registered new interface driver pl2303
[332144.522060] usbserial: USB Serial support registered for pl2303
[332144.522090] pl2303 1-2.1.2:1.0: pl2303 converter detected
[332144.523681] usb 1-2.1.2: pl2303 converter now attached to ttyUSB0

最后一行提到了 ttyUSB0,如果你也想识别删除事件,你可以将它与 1-2.1.2 联系起来:

[332342.342682] usb 1-2.1.2: USB disconnect, device number 6
[332342.342891] pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0
[332342.342903] pl2303 1-2.1.2:1.0: device disconnected

另一种可能性是使用 inotify 系统,当插入驱动器时您可以在其中收到通知。检查 this article on how to use the system .

关于linux - 使用 udevadm 命令的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37947401/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com