I have a udev rule that generates symlinks for my USB devices in /dev
according to their serial number (I have multiple otherwise identical devices but need reproducible device endpoints).
Currently I need to add a rule for every new serial number, like this:
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ATTRS{serial}=="S101", SYMLINK+="ttyS101"
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ATTRS{serial}=="S102", SYMLINK+="ttyS102"
...
I'm looking for a way to do this with a single rule, all that is dynamically accessible is %k
, %n
, and %c
, but I found no way to access any other values. Using PROGRAM=""
might be the way, but how would I access ATTRS from there?
I tried this:
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ATTRS{serial}=="S101", PROGRAM="/bin/sh -c 'udevadm info /dev/%k | grep ID_SERIAL_SHORT= | cut -d= -f 2'" SYMLINK+="tty%c"
but it looks like /dev/%k
is not available when the program runs, so that doesn't work either.
Is there any way to use ATTRS{serial}
for my SYMLINK+=""
?