我只想归还一些我可爱的打印机的数据。(名称始终包含STMicroelectronics printer
我可以用lsusb命令打印出所有插入的USB设备。这将给我(第一行显然是打印机):
Bus 001 Device 004: ID 0483:5743 STMicroelectronics printer-80
Bus 001 Device 003: ID 0424:ec00 Microchip Technology, Inc. (formerly SMSC) SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Microchip Technology, Inc. (formerly SMSC) SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub`我现在可以通过lsusb -vvv -d 0483:5743找到设备的详细信息,它返回:
Bus 001 Device 004: ID 0483:5743 STMicroelectronics printer-80
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x0483 STMicroelectronics
idProduct 0x5743
bcdDevice 1.00
iManufacturer 1 Printer
iProduct 2 printer-80
iSerial 3 012345678AB
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0020
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xc0
Self Powered
MaxPower 2mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 7 Printer
bInterfaceSubClass 1 Printer
bInterfaceProtocol 2 Bidirectional
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable
Device Status: 0x0001
Self Powered现在..。我如何才能通过bash返回这些数据:
idVendor (0x0483)
idProduct (0x5743)
endpointOUT (0x01)
endpointIN (0x81)一定有一些grep/regex魔法,我就是无法掌握。
谢谢您提前提供帮助!
正在寻找解决方案,以使用regex提取包含打印机描述的行。
发布于 2022-11-20 22:36:38
使用GNU sed
$ sed -En 's/[ \t]*b?(id[vp][^ \t]*|endpoint)(address)?[ \t]+([^ \t]*).* (out|in)?.*/\l\1\4 (\3)/Ip' <(lsusb | awk '$0 ~ /STMicroelectronics printer-80/{print $6}' | xargs -I % sh -c "lsusb -vvv -d %")
idVendor (0x0483)
idProduct (0x5743)
endpointOUT (0x01)
endpointIN (0x81)发布于 2022-11-20 22:14:09
建议使用以下awk脚本:
awk '/idVendor/||/idProduct/{printf("%s (%s)\n", $1,$2)}/bEndpointAddress/{printf("endpoint%s (%s)\n", $NF, $2)}' <<<$(lsusb -vvv -d 0483:5743)https://stackoverflow.com/questions/74511582
复制相似问题