Pass ATTR{idVendor} as argument in udev script

linux, shell, udev, usb

Solution

`udev` sets for you several environmental variables that you can use, among others `ID_VENDOR`. Try that little script:

#!/bin/bash

echo "Called by udev" >> /tmp/testenv
env >> /tmp/testenv
echo "Vendor id is $ID_VENDOR" >> /tmp/testenv

Put it in a rule, and you will see how much things are set up for you.

Problem

I have a script which is run whenever a usb device by vendor 1004 is connected. The udev rule I am using works and looks like this. ``` SUBSYSTEM=="usb", ATTR{idVendor}=="1004", RUN+="/var/www/beta/trigger.php" ``` Now I would like to have this script run whenever ANY usb device is connected, and pass the Vendor ID as parameter. (So the script can decide whether it has to be run or not.) Adding a parameter which can be accessed in the script has worked so far: ``` SUBSYSTEM=="usb", RUN+="/var/www/beta/trigger.php myparam" ``` Can someone please tell me how to replace "myparam" with the value of ATTR{idVendor}? I have tried all kinds of combinations, but I never got the expected result... Thanks a lot!

Original source