0

I have a USB device and I need to execute a "infinite" script when I plug in this device and pass the /dev/... path as an argument.

The real example is: The device is RFID reader (0403:6001), which works as tty device. I need to run a script, which reads data from /dev/ttyUSBx and via xdotool prints them into opened web browser. As there could be potentially more devices evaluated as /dev/ttyUSBx, I need to pass the correct one to the script.

The classic way seems to be by udev rule, but I read [1], that the "RUN" parameter is not for long time running scripts. Other than that, I cannot find env variable or %variable that would contain the "ttyUSBx".

Another way I found is by systemd, but the classification of device looks like /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2 which depends on the USB port...

I am running Debian 8 Jessie.

[1] https://www.freedesktop.org/software/systemd/man/udev.html

mkudlacek
  • 1,657
  • 1
  • 11
  • 15
  • I think you can find the answer in [this post](https://unix.stackexchange.com/questions/28548/how-to-run-custom-scripts-upon-usb-device-plug-in) – Esteban May 17 '17 at 06:54
  • Your linked post shows how to do it via udev. As I mention, udev is not for long running scripts. I edited my question with a reference, look for "starting daemons" – mkudlacek May 17 '17 at 07:58
  • It seems you can "combine" udev and systemd as described here, but never tried it myself : http://stackoverflow.com/a/18464973/7990687 – Esteban May 17 '17 at 09:52
  • Using SYSTEMD_WANTS in an udev rule as in the linked comment above is correct. – Tollef Fog Heen May 20 '17 at 07:37

0 Answers0