linux脚本获取usb设备,Linux基于USB端口执行脚本

您应该弄清楚您的外部端口与哪个USB总线连接。在我的电脑上所有外部USB端口都连接到Bus 01

要做这个检查lsusb -t的输出,然后附上一个usb设备并再次检查输出lsusb -t。那么你知道什么是 '不会忽略' 你的三个外部USB端口在你的设备内部USB结构树:

内部USB端口:

/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/5p, 12M

/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/5p, 12M

/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/5p, 480M

|__ Port 1: Dev 64, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M

|__ Port 1: Dev 64, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M

外部USB端口:

/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/5p, 480M

|__ Port 3: Dev 116, If 0, Class='bInterfaceClass 0xe0 not yet handled', Driver=rndis_host, 480M

|__ Port 3: Dev 116, If 1, Class=data, Driver=rndis_host, 480M

USB记忆棒连接到外部端口#2

/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/5p, 480M

|__ Port 2: Dev 119, If 0, Class=stor., Driver=usb-storage, 480M

|__ Port 3: Dev 116, If 0, Class='bInterfaceClass 0xe0 not yet handled', Driver=rndis_host, 480M

|__ Port 3: Dev 116, If 1, Class=data, Driver=rndis_host, 480M

此程序后,您的'地址'您的外部USB端口

在dmesg连接的USB设备总是与包含USB总线和端口号的行出现:

[186067.360139] usb 1-1: new high-speed USB device number 123 using ehci_hcd是总线001的端口001

[186067.360139] usb 1-2: new high-speed USB device number 123 using ehci_hcd是总线001的端口002

[186067.360139] usb 1-3: new high-speed USB device number 123 using ehci_hcd是总线001端口003

你可以得到的端口号直接使用命令

dmesg | grep -o -P 'usb 1.{0,3}' | tail -1 | head -c 7 | tail -c 1(如果您的所有外部端口上Bus 001)

因此,您可以获得最新USB设备(您的设备)所连接的USB端口号,您可以在udev脚本中使用该端口号(if ...)

你也可以找到在/dev/bus/usb/文件系统正即总线01端口1 USB总线树结构/dev/bus/usb/001/001

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值