Simple udev rule does not execute RUN

Having troubles setting up a simple udev rule.

pi@raspberrypi:~ $ ls -l /home/pi/test.sh
-rwxr-xr-x 1 pi pi 37 Jun 25 15:20 /home/pi/test.sh  # executable
pi@raspberrypi:~ $ cat /home/pi/test.sh
#!/bin/sh
echo asdf >> /tmp/asdf.txt       # this works when run manually
pi@raspberrypi:~ $ cat /etc/udev/rules.d/10-usb-uart.rules
SUBSYSTEM=="tty", ACTION=="add", ATTRS{idVendor}=="0403", RUN+="/home/pi/test.sh"

I got ATTRS{idVendor}=="0403" from this:

pi@raspberrypi:~ $ sudo udevadm info -a /dev/ttyUSB0
 looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0':
    KERNEL=="ttyUSB0"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0':
    KERNELS=="ttyUSB0"
    ...
    ATTRS{port_number}=="0"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0':
    KERNELS=="1-1.3:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="ftdi_sio"
    ATTRS{authorized}=="1"
    ...
    ATTRS{supports_autosuspend}=="1"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3':
    KERNELS=="1-1.3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ...
    ATTRS{devnum}=="8"
    ATTRS{devpath}=="1.3"
    ATTRS{devspec}=="  (null)"
    ATTRS{idProduct}=="6001"
    ATTRS{idVendor}=="0403"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="FTDI"
    ...

Yet, no output on file when I connect or disconnect the USB device.


udevadm test:

pi@raspberrypi:~ $ udevadm test $(udevadm info -q path -n /dev/ttyUSB0) 2>&1
calling: test
version 232
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

=== trie on-disk ===
tool version:          232
file size:         8788458 bytes
header size             80 bytes
strings            1851626 bytes
nodes              6936752 bytes
Load module index
Found container virtualization none
timestamp of '/etc/systemd/network' changed
timestamp of '/lib/systemd/network' changed
Skipping overridden file: /lib/systemd/network/99-default.link.
Skipping empty file: /etc/systemd/network/99-default.link
Created link configuration context.
timestamp of '/etc/udev/rules.d' changed
Reading rules file: /lib/udev/rules.d/10-local-rpi.rules
Reading rules file: /etc/udev/rules.d/10-usb-uart.rules       # my file
Reading rules file: /lib/udev/rules.d/15-i2c-modprobe.rules
Reading rules file: /lib/udev/rules.d/40-scratch.rules
Reading rules file: /lib/udev/rules.d/40-usb_modeswitch.rules
Reading rules file: /lib/udev/rules.d/50-firmware.rules
Reading rules file: /lib/udev/rules.d/50-udev-default.rules
Reading rules file: /lib/udev/rules.d/55-dm.rules
Reading rules file: /lib/udev/rules.d/60-block.rules
Reading rules file: /lib/udev/rules.d/60-bluealsa.rules
Reading rules file: /lib/udev/rules.d/60-cdrom_id.rules
Reading rules file: /lib/udev/rules.d/60-crda.rules
Reading rules file: /lib/udev/rules.d/60-drm.rules
Reading rules file: /lib/udev/rules.d/60-evdev.rules
Reading rules file: /lib/udev/rules.d/60-fuse.rules
Reading rules file: /lib/udev/rules.d/60-i2c-tools.rules
Reading rules file: /lib/udev/rules.d/60-libgphoto2-6.rules
Reading rules file: /lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /lib/udev/rules.d/60-persistent-input.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-dm.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage.rules
Reading rules file: /lib/udev/rules.d/60-persistent-v4l.rules
Reading rules file: /lib/udev/rules.d/60-serial.rules
Reading rules file: /lib/udev/rules.d/60-triggerhappy.rules
Reading rules file: /lib/udev/rules.d/64-btrfs.rules
Reading rules file: /lib/udev/rules.d/64-xorg-xkb.rules
Reading rules file: /lib/udev/rules.d/65-libwacom.rules
Reading rules file: /lib/udev/rules.d/69-libmtp.rules
Reading rules file: /lib/udev/rules.d/70-debian-uaccess.rules
Reading rules file: /lib/udev/rules.d/70-mouse.rules
Reading rules file: /lib/udev/rules.d/70-power-switch.rules
Reading rules file: /lib/udev/rules.d/70-touchpad.rules
Reading rules file: /lib/udev/rules.d/70-uaccess.rules
Reading rules file: /lib/udev/rules.d/71-seat.rules
Reading rules file: /lib/udev/rules.d/73-seat-late.rules
Reading rules file: /lib/udev/rules.d/73-special-net-names.rules
Reading rules file: /lib/udev/rules.d/73-usb-net-by-mac.rules
Reading rules file: /lib/udev/rules.d/75-net-description.rules
Reading rules file: /lib/udev/rules.d/75-probe_mtd.rules
Reading rules file: /lib/udev/rules.d/78-sound-card.rules
Reading rules file: /lib/udev/rules.d/80-debian-compat.rules
Reading rules file: /lib/udev/rules.d/80-drivers.rules
Reading rules file: /lib/udev/rules.d/80-ifupdown.rules
Reading rules file: /lib/udev/rules.d/80-libinput-device-groups.rules
Reading rules file: /lib/udev/rules.d/80-net-setup-link.rules
Reading rules file: /lib/udev/rules.d/80-udisks2.rules
Reading rules file: /lib/udev/rules.d/85-hwclock.rules
Reading rules file: /lib/udev/rules.d/85-regulatory.rules
Reading rules file: /lib/udev/rules.d/90-alsa-restore.rules
Reading rules file: /lib/udev/rules.d/90-console-setup.rules
Reading rules file: /lib/udev/rules.d/90-libinput-model-quirks.rules
Reading rules file: /lib/udev/rules.d/90-pi-bluetooth.rules
Reading rules file: /lib/udev/rules.d/95-wedo.rules
Reading rules file: /lib/udev/rules.d/97-hid2hci.rules
Reading rules file: /etc/udev/rules.d/99-com.rules
Reading rules file: /lib/udev/rules.d/99-systemd.rules
rules contain 196608 bytes tokens (16384 * 12 bytes), 24141 bytes strings
17173 strings (139139 bytes), 14825 de-duplicated (117347 bytes), 2349 trie nodes used
RUN '/home/pi/test.sh' /etc/udev/rules.d/10-usb-uart.rules:1
PROGRAM 'usb_modeswitch --symlink-name /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0 0403 6001 ' /lib/udev/rules.d/40-usb_modeswitch.rules:10
starting 'usb_modeswitch --symlink-name /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0 0403 6001 '
Process 'usb_modeswitch --symlink-name /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0 0403 6001 ' succeeded.
GROUP 20 /lib/udev/rules.d/50-udev-default.rules:26
IMPORT builtin 'usb_id' /lib/udev/rules.d/60-serial.rules:8
/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0: if_class 255 protocol 0
IMPORT builtin 'hwdb' /lib/udev/rules.d/60-serial.rules:8
IMPORT builtin 'path_id' /lib/udev/rules.d/60-serial.rules:15
LINK 'serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0' /lib/udev/rules.d/60-serial.rules:17
IMPORT builtin skip 'usb_id' /lib/udev/rules.d/60-serial.rules:19
LINK 'serial/by-id/usb-FTDI_TTL232R-3V3_FT98J77X-if00-port0' /lib/udev/rules.d/60-serial.rules:24
handling device node '/dev/ttyUSB0', devnum=c188:0, mode=0660, uid=0, gid=20
preserve permissions /dev/ttyUSB0, 020660, uid=0, gid=20
preserve already existing symlink '/dev/char/188:0' to '../ttyUSB0'
found 'c188:0' claiming '/run/udev/links/x2fserialx2fby-idx2fusb-FTDI_TTL232R-3V3_FT98J77X-if00-port0'
creating link '/dev/serial/by-id/usb-FTDI_TTL232R-3V3_FT98J77X-if00-port0' to '/dev/ttyUSB0'
preserve already existing symlink '/dev/serial/by-id/usb-FTDI_TTL232R-3V3_FT98J77X-if00-port0' to '../../ttyUSB0'
found 'c188:0' claiming '/run/udev/links/x2fserialx2fby-pathx2fplatform-3f980000.usb-usb-0:1.3:1.0-port0'
creating link '/dev/serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0' to '/dev/ttyUSB0'
preserve already existing symlink '/dev/serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0' to '../../ttyUSB0'
.ID_PORT=0
ACTION=add
DEVLINKS=/dev/serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0 /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FT98J77X-if00-port0
DEVNAME=/dev/ttyUSB0
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0
ID_BUS=usb
ID_MODEL=TTL232R-3V3
ID_MODEL_ENC=TTL232R-3V3
ID_MODEL_FROM_DATABASE=FT232 Serial (UART) IC
ID_MODEL_ID=6001
ID_PATH=platform-3f980000.usb-usb-0:1.3:1.0
ID_PATH_TAG=platform-3f980000_usb-usb-0_1_3_1_0
ID_REVISION=0600
ID_SERIAL=FTDI_TTL232R-3V3_FT98J77X
ID_SERIAL_SHORT=FT98J77X
ID_TYPE=generic
ID_USB_DRIVER=ftdi_sio
ID_USB_INTERFACES=:ffffff:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=FTDI
ID_VENDOR_ENC=FTDI
ID_VENDOR_FROM_DATABASE=Future Technology Devices International, Ltd
ID_VENDOR_ID=0403
MAJOR=188
MINOR=0
SUBSYSTEM=tty
TAGS=:systemd:
USEC_INITIALIZED=321019972
run: '/home/pi/test.sh'                                   # That's good!
Unload module index
Unloaded link configuration context.

The “run” at the end is correct. So is ACTION, and ID_VENDOR_ID.

So, “RUN” seems fine, but no output comes to /tmp/asdf.txt.


udevadm monitor:

KERNEL[972.728210] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 (usb)
KERNEL[972.734972] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
KERNEL[972.735197] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0 (usb-serial)
KERNEL[972.736614] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0 (tty)
UDEV  [972.757922] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 (usb)
UDEV  [972.765063] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV  [972.770564] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0 (usb-serial)
UDEV  [972.798201] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0 (tty)

And udevadm monitor --property:

UDEV  [1280.772278] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0 (tty)
.ID_PORT=0
ACTION=add
DEVLINKS=/dev/serial/by-path/platform-3f980000.usb-usb-0:1.2:1.0-port0 /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FT98J77X-if00-port0
DEVNAME=/dev/ttyUSB0
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0
ID_BUS=usb
ID_MODEL=TTL232R-3V3
ID_MODEL_ENC=TTL232R-3V3
ID_MODEL_FROM_DATABASE=FT232 Serial (UART) IC
ID_MODEL_ID=6001
ID_PATH=platform-3f980000.usb-usb-0:1.2:1.0
ID_PATH_TAG=platform-3f980000_usb-usb-0_1_2_1_0
ID_REVISION=0600
ID_SERIAL=FTDI_TTL232R-3V3_FT98J77X
ID_SERIAL_SHORT=FT98J77X
ID_TYPE=generic
ID_USB_DRIVER=ftdi_sio
ID_USB_INTERFACES=:ffffff:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=FTDI
ID_VENDOR_ENC=FTDI
ID_VENDOR_FROM_DATABASE=Future Technology Devices International, Ltd
ID_VENDOR_ID=0403
MAJOR=188
MINOR=0
SEQNUM=3895
SUBSYSTEM=tty
TAGS=:systemd:
USEC_INITIALIZED=1280765243

This one has no “RUN”.

udevadm monitor --property still shows output. No “RUN” field though. I don’t know if I should expect it to show up there? udevadm test showed it, so I’m surprised udevadm monitor --property didn’t.


I’ve tried changing the name 10-usb-uart.rules to 98-usb-uart.rules, to no av.


Should I expect udevadm monitor --property to show run, as udevadm test does?

What more can I execute to debug what is going on?

Go to Source
Author: Gauthier