udev-rule not executing when connecting device





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















My goal is to do different things, whenever a usb device is plugged in. I found out the kernel-path to my usb-stick when i plug it in which is



/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


I can now run



udevadm info -a -p /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


which gives me



Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

looking at device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda':
KERNEL=="sda"
SUBSYSTEM=="block"
DRIVER==""
ATTR{SUBSYSTEM}=="block"
ATTR{DEVTYPE}=="disk"
ATTR{MAJOR}=="8"
ATTR{MINOR}=="0"
ATTR{USEC_INITIALIZED}=="70123316226"
ATTR{ID_VENDOR}=="SanDisk"
ATTR{ID_VENDOR_ENC}=="SanDiskx20"
ATTR{ID_VENDOR_ID}=="0781"
ATTR{ID_MODEL}=="Ultra_Fit"
ATTR{ID_MODEL_ENC}=="Ultrax20Fitx20x20x20x20x20x20x20"
ATTR{ID_MODEL_ID}=="5583"
ATTR{ID_REVISION}=="1.00"
ATTR{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220-0:0"
ATTR{ID_SERIAL_SHORT}=="4C530123260812112220"
ATTR{ID_TYPE}=="disk"
ATTR{ID_INSTANCE}=="0:0"
ATTR{ID_BUS}=="usb"
ATTR{ID_USB_INTERFACES}==":080650:"
ATTR{ID_USB_INTERFACE_NUM}=="00"
ATTR{ID_USB_DRIVER}=="usb-storage"
ATTR{ID_PATH}=="pci-0000:00:14.0-usb-0:2:1.0-scsi-0:0:0:0"
ATTR{ID_PATH_TAG}=="pci-0000_00_14_0-usb-0_2_1_0-scsi-0_0_0_0"
ATTR{ID_FS_UUID}=="9C89-53D7"
ATTR{ID_FS_UUID_ENC}=="9C89-53D7"
ATTR{ID_FS_VERSION}=="FAT32"
ATTR{ID_FS_TYPE}=="vfat"
ATTR{ID_FS_USAGE}=="filesystem"
ATTR{mount_options}=="noatime,utf8,gid=100,umask=002"
ATTR{dir_name}=="usbhd-sda"
ATTR{TAGS}==":systemd:"

looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0':
KERNELS=="0:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{SUBSYSTEM}=="scsi"
ATTRS{DRIVER}=="sd"
ATTRS{DEVTYPE}=="scsi_device"
ATTRS{MODALIAS}=="scsi:t-0x00"

looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0':
KERNELS=="target0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS==""
ATTRS{SUBSYSTEM}=="scsi"
ATTRS{DEVTYPE}=="scsi_target"

looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0':
KERNELS=="host0"
SUBSYSTEMS=="scsi"
DRIVERS==""
ATTRS{SUBSYSTEM}=="scsi"
ATTRS{DEVTYPE}=="scsi_host"

looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0':
KERNELS=="2-2:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="usb-storage"
ATTRS{SUBSYSTEM}=="usb"
ATTRS{DRIVER}=="usb-storage"
ATTRS{DEVTYPE}=="usb_interface"
ATTRS{PRODUCT}=="781/5583/100"
ATTRS{TYPE}=="0/0/0"
ATTRS{INTERFACE}=="8/6/80"
ATTRS{MODALIAS}=="usb:v0781p5583d0100dc00dsc00dp00ic08isc06ip50in00"
ATTRS{USEC_INITIALIZED}=="70122189776"
ATTRS{ID_VENDOR_FROM_DATABASE}=="SanDisk Corp."
ATTRS{ID_MODEL_FROM_DATABASE}=="Ultra Fit"

looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2':
KERNELS=="2-2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{SUBSYSTEM}=="usb"
ATTRS{DRIVER}=="usb"
ATTRS{DEVTYPE}=="usb_device"
ATTRS{PRODUCT}=="781/5583/100"
ATTRS{TYPE}=="0/0/0"
ATTRS{BUSNUM}=="002"
ATTRS{DEVNUM}=="029"
ATTRS{MAJOR}=="189"
ATTRS{MINOR}=="156"
ATTRS{USEC_INITIALIZED}=="70122175758"
ATTRS{ID_VENDOR}=="SanDisk"
ATTRS{ID_VENDOR_ENC}=="SanDisk"
ATTRS{ID_VENDOR_ID}=="0781"
ATTRS{ID_MODEL}=="Ultra_Fit"
ATTRS{ID_MODEL_ENC}=="Ultrax20Fit"
ATTRS{ID_MODEL_ID}=="5583"
ATTRS{ID_REVISION}=="0100"
ATTRS{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220"
ATTRS{ID_SERIAL_SHORT}=="4C530123260812112220"
ATTRS{ID_BUS}=="usb"
ATTRS{ID_USB_INTERFACES}==":080650:"
ATTRS{ID_VENDOR_FROM_DATABASE}=="SanDisk Corp."
ATTRS{ID_MODEL_FROM_DATABASE}=="Ultra Fit"

looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2':
KERNELS=="usb2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{SUBSYSTEM}=="usb"
ATTRS{DRIVER}=="usb"
ATTRS{DEVTYPE}=="usb_device"
ATTRS{PRODUCT}=="1d6b/3/420"
ATTRS{TYPE}=="9/0/3"
ATTRS{BUSNUM}=="002"
ATTRS{DEVNUM}=="001"
ATTRS{MAJOR}=="189"
ATTRS{MINOR}=="128"
ATTRS{USEC_INITIALIZED}=="1693784"
ATTRS{ID_VENDOR}=="Linux_4.20.6-arch1-1-ARCH_xhci-hcd"
ATTRS{ID_VENDOR_ENC}=="Linuxx204.20.6-arch1-1-ARCHx20xhci-hcd"
ATTRS{ID_VENDOR_ID}=="1d6b"
ATTRS{ID_MODEL}=="xHCI_Host_Controller"
ATTRS{ID_MODEL_ENC}=="xHCIx20Hostx20Controller"
ATTRS{ID_MODEL_ID}=="0003"
ATTRS{ID_REVISION}=="0420"
ATTRS{ID_SERIAL}=="Linux_4.20.6-arch1-1-ARCH_xhci-hcd_xHCI_Host_Controller_0000:00:14.0"
ATTRS{ID_SERIAL_SHORT}=="0000:00:14.0"
ATTRS{ID_BUS}=="usb"
ATTRS{ID_USB_INTERFACES}==":090000:"
ATTRS{ID_VENDOR_FROM_DATABASE}=="Linux Foundation"
ATTRS{ID_MODEL_FROM_DATABASE}=="3.0 root hub"
ATTRS{ID_PATH}=="pci-0000:00:14.0"
ATTRS{ID_PATH_TAG}=="pci-0000_00_14_0"
ATTRS{ID_FOR_SEAT}=="usb-pci-0000_00_14_0"
ATTRS{TAGS}==":seat:"

looking at parent device '//devices/pci0000:00/0000:00:14.0':
KERNELS=="0000:00:14.0"
SUBSYSTEMS=="pci"
DRIVERS=="xhci_hcd"
ATTRS{SUBSYSTEM}=="pci"
ATTRS{DRIVER}=="xhci_hcd"
ATTRS{PCI_CLASS}=="C0330"
ATTRS{PCI_ID}=="8086:9D2F"
ATTRS{PCI_SUBSYS_ID}=="17AA:224F"
ATTRS{PCI_SLOT_NAME}=="0000:00:14.0"
ATTRS{MODALIAS}=="pci:v00008086d00009D2Fsv000017AAsd0000224Fbc0Csc03i30"
ATTRS{USEC_INITIALIZED}=="1690169"
ATTRS{ID_PCI_CLASS_FROM_DATABASE}=="Serial bus controller"
ATTRS{ID_PCI_SUBCLASS_FROM_DATABASE}=="USB controller"
ATTRS{ID_PCI_INTERFACE_FROM_DATABASE}=="XHCI"
ATTRS{ID_VENDOR_FROM_DATABASE}=="Intel Corporation"
ATTRS{ID_MODEL_FROM_DATABASE}=="Sunrise Point-LP USB 3.0 xHCI Controller"

looking at parent device '//devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""


I then wrote a simple udev rule:



tim@x1carbon ~> cat /etc/udev/rules.d/10-rule.rules
SUBSYSTEMS=="usb",ACTION=="add", ATTRS{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220", RUN+="/usr/bin/touch /home/tim/test.txt"⏎
tim@x1carbon ~>


And ran udevadm control -R to reload udev. When i now test with



udevadm test /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


My rule shows up, but when i plug in my device, nothing happens. Can someone help me out?










share|improve this question





























    0















    My goal is to do different things, whenever a usb device is plugged in. I found out the kernel-path to my usb-stick when i plug it in which is



    /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


    I can now run



    udevadm info -a -p /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


    which gives me



    Udevadm info starts with the device specified by the devpath and then
    walks up the chain of parent devices. It prints for every device
    found, all possible attributes in the udev rules key format.
    A rule to match, can be composed by the attributes of the device
    and the attributes from one single parent device.

    looking at device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda':
    KERNEL=="sda"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{SUBSYSTEM}=="block"
    ATTR{DEVTYPE}=="disk"
    ATTR{MAJOR}=="8"
    ATTR{MINOR}=="0"
    ATTR{USEC_INITIALIZED}=="70123316226"
    ATTR{ID_VENDOR}=="SanDisk"
    ATTR{ID_VENDOR_ENC}=="SanDiskx20"
    ATTR{ID_VENDOR_ID}=="0781"
    ATTR{ID_MODEL}=="Ultra_Fit"
    ATTR{ID_MODEL_ENC}=="Ultrax20Fitx20x20x20x20x20x20x20"
    ATTR{ID_MODEL_ID}=="5583"
    ATTR{ID_REVISION}=="1.00"
    ATTR{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220-0:0"
    ATTR{ID_SERIAL_SHORT}=="4C530123260812112220"
    ATTR{ID_TYPE}=="disk"
    ATTR{ID_INSTANCE}=="0:0"
    ATTR{ID_BUS}=="usb"
    ATTR{ID_USB_INTERFACES}==":080650:"
    ATTR{ID_USB_INTERFACE_NUM}=="00"
    ATTR{ID_USB_DRIVER}=="usb-storage"
    ATTR{ID_PATH}=="pci-0000:00:14.0-usb-0:2:1.0-scsi-0:0:0:0"
    ATTR{ID_PATH_TAG}=="pci-0000_00_14_0-usb-0_2_1_0-scsi-0_0_0_0"
    ATTR{ID_FS_UUID}=="9C89-53D7"
    ATTR{ID_FS_UUID_ENC}=="9C89-53D7"
    ATTR{ID_FS_VERSION}=="FAT32"
    ATTR{ID_FS_TYPE}=="vfat"
    ATTR{ID_FS_USAGE}=="filesystem"
    ATTR{mount_options}=="noatime,utf8,gid=100,umask=002"
    ATTR{dir_name}=="usbhd-sda"
    ATTR{TAGS}==":systemd:"

    looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0':
    KERNELS=="0:0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{SUBSYSTEM}=="scsi"
    ATTRS{DRIVER}=="sd"
    ATTRS{DEVTYPE}=="scsi_device"
    ATTRS{MODALIAS}=="scsi:t-0x00"

    looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0':
    KERNELS=="target0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS==""
    ATTRS{SUBSYSTEM}=="scsi"
    ATTRS{DEVTYPE}=="scsi_target"

    looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0':
    KERNELS=="host0"
    SUBSYSTEMS=="scsi"
    DRIVERS==""
    ATTRS{SUBSYSTEM}=="scsi"
    ATTRS{DEVTYPE}=="scsi_host"

    looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0':
    KERNELS=="2-2:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb-storage"
    ATTRS{SUBSYSTEM}=="usb"
    ATTRS{DRIVER}=="usb-storage"
    ATTRS{DEVTYPE}=="usb_interface"
    ATTRS{PRODUCT}=="781/5583/100"
    ATTRS{TYPE}=="0/0/0"
    ATTRS{INTERFACE}=="8/6/80"
    ATTRS{MODALIAS}=="usb:v0781p5583d0100dc00dsc00dp00ic08isc06ip50in00"
    ATTRS{USEC_INITIALIZED}=="70122189776"
    ATTRS{ID_VENDOR_FROM_DATABASE}=="SanDisk Corp."
    ATTRS{ID_MODEL_FROM_DATABASE}=="Ultra Fit"

    looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2':
    KERNELS=="2-2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{SUBSYSTEM}=="usb"
    ATTRS{DRIVER}=="usb"
    ATTRS{DEVTYPE}=="usb_device"
    ATTRS{PRODUCT}=="781/5583/100"
    ATTRS{TYPE}=="0/0/0"
    ATTRS{BUSNUM}=="002"
    ATTRS{DEVNUM}=="029"
    ATTRS{MAJOR}=="189"
    ATTRS{MINOR}=="156"
    ATTRS{USEC_INITIALIZED}=="70122175758"
    ATTRS{ID_VENDOR}=="SanDisk"
    ATTRS{ID_VENDOR_ENC}=="SanDisk"
    ATTRS{ID_VENDOR_ID}=="0781"
    ATTRS{ID_MODEL}=="Ultra_Fit"
    ATTRS{ID_MODEL_ENC}=="Ultrax20Fit"
    ATTRS{ID_MODEL_ID}=="5583"
    ATTRS{ID_REVISION}=="0100"
    ATTRS{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220"
    ATTRS{ID_SERIAL_SHORT}=="4C530123260812112220"
    ATTRS{ID_BUS}=="usb"
    ATTRS{ID_USB_INTERFACES}==":080650:"
    ATTRS{ID_VENDOR_FROM_DATABASE}=="SanDisk Corp."
    ATTRS{ID_MODEL_FROM_DATABASE}=="Ultra Fit"

    looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2':
    KERNELS=="usb2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{SUBSYSTEM}=="usb"
    ATTRS{DRIVER}=="usb"
    ATTRS{DEVTYPE}=="usb_device"
    ATTRS{PRODUCT}=="1d6b/3/420"
    ATTRS{TYPE}=="9/0/3"
    ATTRS{BUSNUM}=="002"
    ATTRS{DEVNUM}=="001"
    ATTRS{MAJOR}=="189"
    ATTRS{MINOR}=="128"
    ATTRS{USEC_INITIALIZED}=="1693784"
    ATTRS{ID_VENDOR}=="Linux_4.20.6-arch1-1-ARCH_xhci-hcd"
    ATTRS{ID_VENDOR_ENC}=="Linuxx204.20.6-arch1-1-ARCHx20xhci-hcd"
    ATTRS{ID_VENDOR_ID}=="1d6b"
    ATTRS{ID_MODEL}=="xHCI_Host_Controller"
    ATTRS{ID_MODEL_ENC}=="xHCIx20Hostx20Controller"
    ATTRS{ID_MODEL_ID}=="0003"
    ATTRS{ID_REVISION}=="0420"
    ATTRS{ID_SERIAL}=="Linux_4.20.6-arch1-1-ARCH_xhci-hcd_xHCI_Host_Controller_0000:00:14.0"
    ATTRS{ID_SERIAL_SHORT}=="0000:00:14.0"
    ATTRS{ID_BUS}=="usb"
    ATTRS{ID_USB_INTERFACES}==":090000:"
    ATTRS{ID_VENDOR_FROM_DATABASE}=="Linux Foundation"
    ATTRS{ID_MODEL_FROM_DATABASE}=="3.0 root hub"
    ATTRS{ID_PATH}=="pci-0000:00:14.0"
    ATTRS{ID_PATH_TAG}=="pci-0000_00_14_0"
    ATTRS{ID_FOR_SEAT}=="usb-pci-0000_00_14_0"
    ATTRS{TAGS}==":seat:"

    looking at parent device '//devices/pci0000:00/0000:00:14.0':
    KERNELS=="0000:00:14.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
    ATTRS{SUBSYSTEM}=="pci"
    ATTRS{DRIVER}=="xhci_hcd"
    ATTRS{PCI_CLASS}=="C0330"
    ATTRS{PCI_ID}=="8086:9D2F"
    ATTRS{PCI_SUBSYS_ID}=="17AA:224F"
    ATTRS{PCI_SLOT_NAME}=="0000:00:14.0"
    ATTRS{MODALIAS}=="pci:v00008086d00009D2Fsv000017AAsd0000224Fbc0Csc03i30"
    ATTRS{USEC_INITIALIZED}=="1690169"
    ATTRS{ID_PCI_CLASS_FROM_DATABASE}=="Serial bus controller"
    ATTRS{ID_PCI_SUBCLASS_FROM_DATABASE}=="USB controller"
    ATTRS{ID_PCI_INTERFACE_FROM_DATABASE}=="XHCI"
    ATTRS{ID_VENDOR_FROM_DATABASE}=="Intel Corporation"
    ATTRS{ID_MODEL_FROM_DATABASE}=="Sunrise Point-LP USB 3.0 xHCI Controller"

    looking at parent device '//devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""


    I then wrote a simple udev rule:



    tim@x1carbon ~> cat /etc/udev/rules.d/10-rule.rules
    SUBSYSTEMS=="usb",ACTION=="add", ATTRS{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220", RUN+="/usr/bin/touch /home/tim/test.txt"⏎
    tim@x1carbon ~>


    And ran udevadm control -R to reload udev. When i now test with



    udevadm test /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


    My rule shows up, but when i plug in my device, nothing happens. Can someone help me out?










    share|improve this question

























      0












      0








      0








      My goal is to do different things, whenever a usb device is plugged in. I found out the kernel-path to my usb-stick when i plug it in which is



      /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


      I can now run



      udevadm info -a -p /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


      which gives me



      Udevadm info starts with the device specified by the devpath and then
      walks up the chain of parent devices. It prints for every device
      found, all possible attributes in the udev rules key format.
      A rule to match, can be composed by the attributes of the device
      and the attributes from one single parent device.

      looking at device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda':
      KERNEL=="sda"
      SUBSYSTEM=="block"
      DRIVER==""
      ATTR{SUBSYSTEM}=="block"
      ATTR{DEVTYPE}=="disk"
      ATTR{MAJOR}=="8"
      ATTR{MINOR}=="0"
      ATTR{USEC_INITIALIZED}=="70123316226"
      ATTR{ID_VENDOR}=="SanDisk"
      ATTR{ID_VENDOR_ENC}=="SanDiskx20"
      ATTR{ID_VENDOR_ID}=="0781"
      ATTR{ID_MODEL}=="Ultra_Fit"
      ATTR{ID_MODEL_ENC}=="Ultrax20Fitx20x20x20x20x20x20x20"
      ATTR{ID_MODEL_ID}=="5583"
      ATTR{ID_REVISION}=="1.00"
      ATTR{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220-0:0"
      ATTR{ID_SERIAL_SHORT}=="4C530123260812112220"
      ATTR{ID_TYPE}=="disk"
      ATTR{ID_INSTANCE}=="0:0"
      ATTR{ID_BUS}=="usb"
      ATTR{ID_USB_INTERFACES}==":080650:"
      ATTR{ID_USB_INTERFACE_NUM}=="00"
      ATTR{ID_USB_DRIVER}=="usb-storage"
      ATTR{ID_PATH}=="pci-0000:00:14.0-usb-0:2:1.0-scsi-0:0:0:0"
      ATTR{ID_PATH_TAG}=="pci-0000_00_14_0-usb-0_2_1_0-scsi-0_0_0_0"
      ATTR{ID_FS_UUID}=="9C89-53D7"
      ATTR{ID_FS_UUID_ENC}=="9C89-53D7"
      ATTR{ID_FS_VERSION}=="FAT32"
      ATTR{ID_FS_TYPE}=="vfat"
      ATTR{ID_FS_USAGE}=="filesystem"
      ATTR{mount_options}=="noatime,utf8,gid=100,umask=002"
      ATTR{dir_name}=="usbhd-sda"
      ATTR{TAGS}==":systemd:"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0':
      KERNELS=="0:0:0:0"
      SUBSYSTEMS=="scsi"
      DRIVERS=="sd"
      ATTRS{SUBSYSTEM}=="scsi"
      ATTRS{DRIVER}=="sd"
      ATTRS{DEVTYPE}=="scsi_device"
      ATTRS{MODALIAS}=="scsi:t-0x00"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0':
      KERNELS=="target0:0:0"
      SUBSYSTEMS=="scsi"
      DRIVERS==""
      ATTRS{SUBSYSTEM}=="scsi"
      ATTRS{DEVTYPE}=="scsi_target"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0':
      KERNELS=="host0"
      SUBSYSTEMS=="scsi"
      DRIVERS==""
      ATTRS{SUBSYSTEM}=="scsi"
      ATTRS{DEVTYPE}=="scsi_host"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0':
      KERNELS=="2-2:1.0"
      SUBSYSTEMS=="usb"
      DRIVERS=="usb-storage"
      ATTRS{SUBSYSTEM}=="usb"
      ATTRS{DRIVER}=="usb-storage"
      ATTRS{DEVTYPE}=="usb_interface"
      ATTRS{PRODUCT}=="781/5583/100"
      ATTRS{TYPE}=="0/0/0"
      ATTRS{INTERFACE}=="8/6/80"
      ATTRS{MODALIAS}=="usb:v0781p5583d0100dc00dsc00dp00ic08isc06ip50in00"
      ATTRS{USEC_INITIALIZED}=="70122189776"
      ATTRS{ID_VENDOR_FROM_DATABASE}=="SanDisk Corp."
      ATTRS{ID_MODEL_FROM_DATABASE}=="Ultra Fit"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2':
      KERNELS=="2-2"
      SUBSYSTEMS=="usb"
      DRIVERS=="usb"
      ATTRS{SUBSYSTEM}=="usb"
      ATTRS{DRIVER}=="usb"
      ATTRS{DEVTYPE}=="usb_device"
      ATTRS{PRODUCT}=="781/5583/100"
      ATTRS{TYPE}=="0/0/0"
      ATTRS{BUSNUM}=="002"
      ATTRS{DEVNUM}=="029"
      ATTRS{MAJOR}=="189"
      ATTRS{MINOR}=="156"
      ATTRS{USEC_INITIALIZED}=="70122175758"
      ATTRS{ID_VENDOR}=="SanDisk"
      ATTRS{ID_VENDOR_ENC}=="SanDisk"
      ATTRS{ID_VENDOR_ID}=="0781"
      ATTRS{ID_MODEL}=="Ultra_Fit"
      ATTRS{ID_MODEL_ENC}=="Ultrax20Fit"
      ATTRS{ID_MODEL_ID}=="5583"
      ATTRS{ID_REVISION}=="0100"
      ATTRS{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220"
      ATTRS{ID_SERIAL_SHORT}=="4C530123260812112220"
      ATTRS{ID_BUS}=="usb"
      ATTRS{ID_USB_INTERFACES}==":080650:"
      ATTRS{ID_VENDOR_FROM_DATABASE}=="SanDisk Corp."
      ATTRS{ID_MODEL_FROM_DATABASE}=="Ultra Fit"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2':
      KERNELS=="usb2"
      SUBSYSTEMS=="usb"
      DRIVERS=="usb"
      ATTRS{SUBSYSTEM}=="usb"
      ATTRS{DRIVER}=="usb"
      ATTRS{DEVTYPE}=="usb_device"
      ATTRS{PRODUCT}=="1d6b/3/420"
      ATTRS{TYPE}=="9/0/3"
      ATTRS{BUSNUM}=="002"
      ATTRS{DEVNUM}=="001"
      ATTRS{MAJOR}=="189"
      ATTRS{MINOR}=="128"
      ATTRS{USEC_INITIALIZED}=="1693784"
      ATTRS{ID_VENDOR}=="Linux_4.20.6-arch1-1-ARCH_xhci-hcd"
      ATTRS{ID_VENDOR_ENC}=="Linuxx204.20.6-arch1-1-ARCHx20xhci-hcd"
      ATTRS{ID_VENDOR_ID}=="1d6b"
      ATTRS{ID_MODEL}=="xHCI_Host_Controller"
      ATTRS{ID_MODEL_ENC}=="xHCIx20Hostx20Controller"
      ATTRS{ID_MODEL_ID}=="0003"
      ATTRS{ID_REVISION}=="0420"
      ATTRS{ID_SERIAL}=="Linux_4.20.6-arch1-1-ARCH_xhci-hcd_xHCI_Host_Controller_0000:00:14.0"
      ATTRS{ID_SERIAL_SHORT}=="0000:00:14.0"
      ATTRS{ID_BUS}=="usb"
      ATTRS{ID_USB_INTERFACES}==":090000:"
      ATTRS{ID_VENDOR_FROM_DATABASE}=="Linux Foundation"
      ATTRS{ID_MODEL_FROM_DATABASE}=="3.0 root hub"
      ATTRS{ID_PATH}=="pci-0000:00:14.0"
      ATTRS{ID_PATH_TAG}=="pci-0000_00_14_0"
      ATTRS{ID_FOR_SEAT}=="usb-pci-0000_00_14_0"
      ATTRS{TAGS}==":seat:"

      looking at parent device '//devices/pci0000:00/0000:00:14.0':
      KERNELS=="0000:00:14.0"
      SUBSYSTEMS=="pci"
      DRIVERS=="xhci_hcd"
      ATTRS{SUBSYSTEM}=="pci"
      ATTRS{DRIVER}=="xhci_hcd"
      ATTRS{PCI_CLASS}=="C0330"
      ATTRS{PCI_ID}=="8086:9D2F"
      ATTRS{PCI_SUBSYS_ID}=="17AA:224F"
      ATTRS{PCI_SLOT_NAME}=="0000:00:14.0"
      ATTRS{MODALIAS}=="pci:v00008086d00009D2Fsv000017AAsd0000224Fbc0Csc03i30"
      ATTRS{USEC_INITIALIZED}=="1690169"
      ATTRS{ID_PCI_CLASS_FROM_DATABASE}=="Serial bus controller"
      ATTRS{ID_PCI_SUBCLASS_FROM_DATABASE}=="USB controller"
      ATTRS{ID_PCI_INTERFACE_FROM_DATABASE}=="XHCI"
      ATTRS{ID_VENDOR_FROM_DATABASE}=="Intel Corporation"
      ATTRS{ID_MODEL_FROM_DATABASE}=="Sunrise Point-LP USB 3.0 xHCI Controller"

      looking at parent device '//devices/pci0000:00':
      KERNELS=="pci0000:00"
      SUBSYSTEMS==""
      DRIVERS==""


      I then wrote a simple udev rule:



      tim@x1carbon ~> cat /etc/udev/rules.d/10-rule.rules
      SUBSYSTEMS=="usb",ACTION=="add", ATTRS{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220", RUN+="/usr/bin/touch /home/tim/test.txt"⏎
      tim@x1carbon ~>


      And ran udevadm control -R to reload udev. When i now test with



      udevadm test /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


      My rule shows up, but when i plug in my device, nothing happens. Can someone help me out?










      share|improve this question














      My goal is to do different things, whenever a usb device is plugged in. I found out the kernel-path to my usb-stick when i plug it in which is



      /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


      I can now run



      udevadm info -a -p /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


      which gives me



      Udevadm info starts with the device specified by the devpath and then
      walks up the chain of parent devices. It prints for every device
      found, all possible attributes in the udev rules key format.
      A rule to match, can be composed by the attributes of the device
      and the attributes from one single parent device.

      looking at device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda':
      KERNEL=="sda"
      SUBSYSTEM=="block"
      DRIVER==""
      ATTR{SUBSYSTEM}=="block"
      ATTR{DEVTYPE}=="disk"
      ATTR{MAJOR}=="8"
      ATTR{MINOR}=="0"
      ATTR{USEC_INITIALIZED}=="70123316226"
      ATTR{ID_VENDOR}=="SanDisk"
      ATTR{ID_VENDOR_ENC}=="SanDiskx20"
      ATTR{ID_VENDOR_ID}=="0781"
      ATTR{ID_MODEL}=="Ultra_Fit"
      ATTR{ID_MODEL_ENC}=="Ultrax20Fitx20x20x20x20x20x20x20"
      ATTR{ID_MODEL_ID}=="5583"
      ATTR{ID_REVISION}=="1.00"
      ATTR{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220-0:0"
      ATTR{ID_SERIAL_SHORT}=="4C530123260812112220"
      ATTR{ID_TYPE}=="disk"
      ATTR{ID_INSTANCE}=="0:0"
      ATTR{ID_BUS}=="usb"
      ATTR{ID_USB_INTERFACES}==":080650:"
      ATTR{ID_USB_INTERFACE_NUM}=="00"
      ATTR{ID_USB_DRIVER}=="usb-storage"
      ATTR{ID_PATH}=="pci-0000:00:14.0-usb-0:2:1.0-scsi-0:0:0:0"
      ATTR{ID_PATH_TAG}=="pci-0000_00_14_0-usb-0_2_1_0-scsi-0_0_0_0"
      ATTR{ID_FS_UUID}=="9C89-53D7"
      ATTR{ID_FS_UUID_ENC}=="9C89-53D7"
      ATTR{ID_FS_VERSION}=="FAT32"
      ATTR{ID_FS_TYPE}=="vfat"
      ATTR{ID_FS_USAGE}=="filesystem"
      ATTR{mount_options}=="noatime,utf8,gid=100,umask=002"
      ATTR{dir_name}=="usbhd-sda"
      ATTR{TAGS}==":systemd:"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0':
      KERNELS=="0:0:0:0"
      SUBSYSTEMS=="scsi"
      DRIVERS=="sd"
      ATTRS{SUBSYSTEM}=="scsi"
      ATTRS{DRIVER}=="sd"
      ATTRS{DEVTYPE}=="scsi_device"
      ATTRS{MODALIAS}=="scsi:t-0x00"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0':
      KERNELS=="target0:0:0"
      SUBSYSTEMS=="scsi"
      DRIVERS==""
      ATTRS{SUBSYSTEM}=="scsi"
      ATTRS{DEVTYPE}=="scsi_target"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0':
      KERNELS=="host0"
      SUBSYSTEMS=="scsi"
      DRIVERS==""
      ATTRS{SUBSYSTEM}=="scsi"
      ATTRS{DEVTYPE}=="scsi_host"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0':
      KERNELS=="2-2:1.0"
      SUBSYSTEMS=="usb"
      DRIVERS=="usb-storage"
      ATTRS{SUBSYSTEM}=="usb"
      ATTRS{DRIVER}=="usb-storage"
      ATTRS{DEVTYPE}=="usb_interface"
      ATTRS{PRODUCT}=="781/5583/100"
      ATTRS{TYPE}=="0/0/0"
      ATTRS{INTERFACE}=="8/6/80"
      ATTRS{MODALIAS}=="usb:v0781p5583d0100dc00dsc00dp00ic08isc06ip50in00"
      ATTRS{USEC_INITIALIZED}=="70122189776"
      ATTRS{ID_VENDOR_FROM_DATABASE}=="SanDisk Corp."
      ATTRS{ID_MODEL_FROM_DATABASE}=="Ultra Fit"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2/2-2':
      KERNELS=="2-2"
      SUBSYSTEMS=="usb"
      DRIVERS=="usb"
      ATTRS{SUBSYSTEM}=="usb"
      ATTRS{DRIVER}=="usb"
      ATTRS{DEVTYPE}=="usb_device"
      ATTRS{PRODUCT}=="781/5583/100"
      ATTRS{TYPE}=="0/0/0"
      ATTRS{BUSNUM}=="002"
      ATTRS{DEVNUM}=="029"
      ATTRS{MAJOR}=="189"
      ATTRS{MINOR}=="156"
      ATTRS{USEC_INITIALIZED}=="70122175758"
      ATTRS{ID_VENDOR}=="SanDisk"
      ATTRS{ID_VENDOR_ENC}=="SanDisk"
      ATTRS{ID_VENDOR_ID}=="0781"
      ATTRS{ID_MODEL}=="Ultra_Fit"
      ATTRS{ID_MODEL_ENC}=="Ultrax20Fit"
      ATTRS{ID_MODEL_ID}=="5583"
      ATTRS{ID_REVISION}=="0100"
      ATTRS{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220"
      ATTRS{ID_SERIAL_SHORT}=="4C530123260812112220"
      ATTRS{ID_BUS}=="usb"
      ATTRS{ID_USB_INTERFACES}==":080650:"
      ATTRS{ID_VENDOR_FROM_DATABASE}=="SanDisk Corp."
      ATTRS{ID_MODEL_FROM_DATABASE}=="Ultra Fit"

      looking at parent device '//devices/pci0000:00/0000:00:14.0/usb2':
      KERNELS=="usb2"
      SUBSYSTEMS=="usb"
      DRIVERS=="usb"
      ATTRS{SUBSYSTEM}=="usb"
      ATTRS{DRIVER}=="usb"
      ATTRS{DEVTYPE}=="usb_device"
      ATTRS{PRODUCT}=="1d6b/3/420"
      ATTRS{TYPE}=="9/0/3"
      ATTRS{BUSNUM}=="002"
      ATTRS{DEVNUM}=="001"
      ATTRS{MAJOR}=="189"
      ATTRS{MINOR}=="128"
      ATTRS{USEC_INITIALIZED}=="1693784"
      ATTRS{ID_VENDOR}=="Linux_4.20.6-arch1-1-ARCH_xhci-hcd"
      ATTRS{ID_VENDOR_ENC}=="Linuxx204.20.6-arch1-1-ARCHx20xhci-hcd"
      ATTRS{ID_VENDOR_ID}=="1d6b"
      ATTRS{ID_MODEL}=="xHCI_Host_Controller"
      ATTRS{ID_MODEL_ENC}=="xHCIx20Hostx20Controller"
      ATTRS{ID_MODEL_ID}=="0003"
      ATTRS{ID_REVISION}=="0420"
      ATTRS{ID_SERIAL}=="Linux_4.20.6-arch1-1-ARCH_xhci-hcd_xHCI_Host_Controller_0000:00:14.0"
      ATTRS{ID_SERIAL_SHORT}=="0000:00:14.0"
      ATTRS{ID_BUS}=="usb"
      ATTRS{ID_USB_INTERFACES}==":090000:"
      ATTRS{ID_VENDOR_FROM_DATABASE}=="Linux Foundation"
      ATTRS{ID_MODEL_FROM_DATABASE}=="3.0 root hub"
      ATTRS{ID_PATH}=="pci-0000:00:14.0"
      ATTRS{ID_PATH_TAG}=="pci-0000_00_14_0"
      ATTRS{ID_FOR_SEAT}=="usb-pci-0000_00_14_0"
      ATTRS{TAGS}==":seat:"

      looking at parent device '//devices/pci0000:00/0000:00:14.0':
      KERNELS=="0000:00:14.0"
      SUBSYSTEMS=="pci"
      DRIVERS=="xhci_hcd"
      ATTRS{SUBSYSTEM}=="pci"
      ATTRS{DRIVER}=="xhci_hcd"
      ATTRS{PCI_CLASS}=="C0330"
      ATTRS{PCI_ID}=="8086:9D2F"
      ATTRS{PCI_SUBSYS_ID}=="17AA:224F"
      ATTRS{PCI_SLOT_NAME}=="0000:00:14.0"
      ATTRS{MODALIAS}=="pci:v00008086d00009D2Fsv000017AAsd0000224Fbc0Csc03i30"
      ATTRS{USEC_INITIALIZED}=="1690169"
      ATTRS{ID_PCI_CLASS_FROM_DATABASE}=="Serial bus controller"
      ATTRS{ID_PCI_SUBCLASS_FROM_DATABASE}=="USB controller"
      ATTRS{ID_PCI_INTERFACE_FROM_DATABASE}=="XHCI"
      ATTRS{ID_VENDOR_FROM_DATABASE}=="Intel Corporation"
      ATTRS{ID_MODEL_FROM_DATABASE}=="Sunrise Point-LP USB 3.0 xHCI Controller"

      looking at parent device '//devices/pci0000:00':
      KERNELS=="pci0000:00"
      SUBSYSTEMS==""
      DRIVERS==""


      I then wrote a simple udev rule:



      tim@x1carbon ~> cat /etc/udev/rules.d/10-rule.rules
      SUBSYSTEMS=="usb",ACTION=="add", ATTRS{ID_SERIAL}=="SanDisk_Ultra_Fit_4C530123260812112220", RUN+="/usr/bin/touch /home/tim/test.txt"⏎
      tim@x1carbon ~>


      And ran udevadm control -R to reload udev. When i now test with



      udevadm test /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/host0/target0:0:0/0:0:0:0/block/sda


      My rule shows up, but when i plug in my device, nothing happens. Can someone help me out?







      linux usb udev






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 8 at 10:47









      Tim HiltTim Hilt

      4717




      4717






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1403484%2fudev-rule-not-executing-when-connecting-device%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1403484%2fudev-rule-not-executing-when-connecting-device%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Plaza Victoria

          Puebla de Zaragoza

          Musa