我有一个使用命令udevadm
来获取有关/ dev设备的信息的脚本,我的脚本所需的信息是ID_SERIAL
值,因为我想过滤tty's
表示连接到USB端口的特定产品的设备。问题是,环境中存在的udevm的udevadm版本为128
,此版本的udevadm
没有查询property
可用。如何以其他方式过滤usb端口上连接的设备?
编辑1 的 Command.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;
答案 0 :(得分:0)
使用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
,如果您想识别remove-event,也可以将其与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。