I need to be notified once new USB device is attached/detached in Linux system.
And once new device will be attached I need to read the config file("config/conf.xml") and notify to REST API.
I looked into libusb and udev-rules but not sure what is the best way to achieve this.
Please give your view/suggestion on this.
I'd add udev rule first with running your custom script. Something like:
ACTION=="add", KERNEL=="sd?1", SUBSYSTEMS=="usb", RUN+="/path/to/your/script %k"
%k
is kernel parameter that is passed to your script.
From udev man:
$kernel, %k
The kernel name for this device.
In the script I'd use curl
. If you don't need some tricky logic. If so, I'd use python.
Anyway I think udev is perfect for this problem.