Watch USB connections vendor id, product id and revision

You can do that with udevadm:

udevadm monitor --subsystem-match=usb --property

or

udevadm monitor --subsystem-match=usb --property --udev

to filter only udev events. If you want to grep for a particular property you will have to un-buffer udevadm output (with tools like stdbuf, script, unbuffer...):

stdbuf -i 0 -o 0 -e 0 udevadm monitor --subsystem-match=usb --property --udev | grep DEVPATH

or

script -q /dev/null -c "udevadm monitor --subsystem-match=usb --property --udev" | grep PRODUCT

or

unbuffer udevadm monitor --subsystem-match=usb --property --udev | grep -E 'ID_VENDOR_ID|ID_MODEL_ID'

This information appears in the kernel logs — typically in /var/log/kern.log, or /var/log/syslog, or some other file (it depends on your syslog configuration, different distributions have different defaults).

If you'd like something pre-filtered, you can add an udev rule. Create a file /etc/udev/rules.d/tkk-log-usb.rules containing something like:

SUBSYSTEM=="usb", RUN+="/usr/local/sbin/tkk-usb-event"

The environment of the program is populated with a lot of variables describing the device, including:

  • ACTION (add or remove)
  • DEVICE is a path to the device if you want to access it
  • ID_MODEL_ID and ID_VENDOR_ID contain the model and vendor ID, and ID_MODEL and ID_VENDOR contain the corresponding text
  • ID_SERIAL contains the serial number of the device (if available)

Tags:

Linux

Usb

Udev