I have written a simple udev rule to name my usb device:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="ttyUSB-ZStick-5G"

udev offers ways to run custom scripts on certain events (ref:

KERNEL=="sdb", RUN+="/usr/bin/my_program"

However, what i would like for the above solution is to just print some info that will show up in dmesg. This isn't a complexity that would require a separate script.

Below is something what I was ideally hoping to work:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="ttyUSB-ZStick-5G", RUN+="echo 'Made symlink: ttyUSB-ZStick-5G' > /dev/kmsg"

Ideas on how to do this?

  • 1
    udev is not a shell. Use sh -c 'echo ... – don_crissti Mar 15 '16 at 12:00

As the manual explains:

The program name and following arguments are separated by spaces. Single quotes can be used to specify arguments with spaces.

The string passed to RUN is not fed to a shell. It's just split at whitespace with a crude quoting mechanism. If you want to perform a redirection, you need to invoke a shell.

… RUN+="sh -c 'echo Made symlink: ttyUSB-ZStick-5G > /dev/kmsg'"

Calling a script would be clearer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.