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
orremove
)DEVICE
is a path to the device if you want to access itID_MODEL_ID
andID_VENDOR_ID
contain the model and vendor ID, andID_MODEL
andID_VENDOR
contain the corresponding textID_SERIAL
contains the serial number of the device (if available)