2

I'm trying to let my Raspberry Pi (running Debian Jessie) push a notification to Pushbullet when for some reason my HDD is disconnected, using udev rules. Now I've managed to make this work sort of. The problem however is that the script runs 14 times instead of just once and it runs on disconnect AND connect actions, which is not my intention..

I've tried a lot of different configurations of the rules file, such as:

ACTION==”remove”,
KERNEL==”sda1”,
SUBSYSTEM==”block”,
KERNELS==”1-1.2”,
SUBSYSTEMS==”usb”,
ATTRS{idProduct}==”10a2”,
ATTRS{idVendor}==”1058”,
ATTRS{manufacturer}=="Western Digital",
RUN+="/home/pi/HDD_removed.sh"

and

ACTION=="remove",
ENV{ID_MODEL}=="Elements_10A2",
RUN+="/home/pi/HDD_removed.sh"

and others, but nothing works properly..

As a help I printed the outputs of udevadm info and udevadm monitor below (sorry for the large sizes..):

$ udevadm info -a -p $(udevadm info -q path -n /dev/sda1)

looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1':
KERNEL=="sda1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{start}=="2048"
ATTR{inflight}=="       0        0"
ATTR{ro}=="0"
ATTR{partition}=="1"
ATTR{stat}=="     545        0    61544     4110        0        0        0        0        0     1320     4110"
ATTR{size}=="1953456128"
ATTR{alignment_offset}=="0"
ATTR{discard_alignment}=="0"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda':
KERNELS=="sda"
SUBSYSTEMS=="block"
DRIVERS==""
ATTRS{badblocks}==""
ATTRS{range}=="16"
ATTRS{capability}=="50"
ATTRS{inflight}=="       0        0"
ATTRS{ext_range}=="256"
ATTRS{ro}=="0"
ATTRS{stat}=="     590        0    62336     4140        0        0        0        0        0     1350     4140"
ATTRS{events_poll_msecs}=="-1"
ATTRS{events_async}==""
ATTRS{removable}=="0"
ATTRS{size}=="1953458176"
ATTRS{events}==""
ATTRS{alignment_offset}=="0"
ATTRS{discard_alignment}=="0"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0':
KERNELS=="0:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{evt_soft_threshold_reached}=="0"
ATTRS{evt_mode_parameter_change_reported}=="0"
ATTRS{inquiry}==""
ATTRS{evt_capacity_change_reported}=="0"
ATTRS{vendor}=="WD      "
ATTRS{timeout}=="30"
ATTRS{evt_lun_change_reported}=="0"
ATTRS{evt_media_change}=="0"
ATTRS{queue_type}=="none"
ATTRS{device_busy}=="0"
ATTRS{eh_timeout}=="10"
ATTRS{model}=="Elements 10A2   "
ATTRS{iocounterbits}=="32"
ATTRS{queue_depth}=="1"
ATTRS{type}=="0"
ATTRS{evt_inquiry_change_reported}=="0"
ATTRS{max_sectors}=="240"
ATTRS{iodone_cnt}=="0x27d"
ATTRS{state}=="running"
ATTRS{iorequest_cnt}=="0x27d"
ATTRS{rev}=="1033"
ATTRS{ioerr_cnt}=="0x3"
ATTRS{scsi_level}=="7"
ATTRS{device_blocked}=="0"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0':
KERNELS=="target0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS==""

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0':
KERNELS=="host0"
SUBSYSTEMS=="scsi"
DRIVERS==""

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0':
KERNELS=="1-1.2:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="usb-storage"
ATTRS{bInterfaceProtocol}=="50"
ATTRS{bInterfaceNumber}=="00"
ATTRS{bInterfaceSubClass}=="06"
ATTRS{bInterfaceClass}=="08"
ATTRS{bAlternateSetting}==" 0"
ATTRS{authorized}=="1"
ATTRS{bNumEndpoints}=="02"
ATTRS{supports_autosuspend}=="1"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2':
KERNELS=="1-1.2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bDeviceClass}=="00"
ATTRS{manufacturer}=="Western Digital"
ATTRS{bmAttributes}=="80"
ATTRS{bConfigurationValue}=="1"
ATTRS{version}==" 2.10"
ATTRS{devnum}=="9"
ATTRS{bMaxPower}=="100mA"
ATTRS{idProduct}=="10a2"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{urbnum}=="7168"
ATTRS{bDeviceSubClass}=="00"
ATTRS{maxchild}=="0"
ATTRS{bcdDevice}=="1033"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{idVendor}=="1058"
ATTRS{product}=="Elements 10A2"
ATTRS{speed}=="480"
ATTRS{removable}=="removable"
ATTRS{ltm_capable}=="no"
ATTRS{serial}=="575831314541323038393032"
ATTRS{bNumConfigurations}=="1"
ATTRS{busnum}=="1"
ATTRS{authorized}=="1"
ATTRS{quirks}=="0x0"
ATTRS{configuration}==""
ATTRS{devpath}=="1.2"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bNumInterfaces}==" 1"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1':
KERNELS=="1-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bDeviceClass}=="09"
ATTRS{bmAttributes}=="e0"
ATTRS{bConfigurationValue}=="1"
ATTRS{version}==" 2.00"
ATTRS{devnum}=="2"
ATTRS{bMaxPower}=="2mA"
ATTRS{idProduct}=="9514"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{urbnum}=="144"
ATTRS{bDeviceSubClass}=="00"
ATTRS{maxchild}=="5"
ATTRS{bcdDevice}=="0200"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{idVendor}=="0424"
ATTRS{speed}=="480"
ATTRS{removable}=="unknown"
ATTRS{ltm_capable}=="no"
ATTRS{bNumConfigurations}=="1"
ATTRS{busnum}=="1"
ATTRS{authorized}=="1"
ATTRS{quirks}=="0x0"
ATTRS{configuration}==""
ATTRS{devpath}=="1"
ATTRS{bDeviceProtocol}=="02"
ATTRS{bNumInterfaces}==" 1"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1':
KERNELS=="usb1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bDeviceClass}=="09"
ATTRS{manufacturer}=="Linux 4.9.24-v7+ dwc_otg_hcd"
ATTRS{bmAttributes}=="e0"
ATTRS{bConfigurationValue}=="1"
ATTRS{version}==" 2.00"
ATTRS{devnum}=="1"
ATTRS{bMaxPower}=="0mA"
ATTRS{idProduct}=="0002"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{urbnum}=="25"
ATTRS{bDeviceSubClass}=="00"
ATTRS{maxchild}=="1"
ATTRS{bcdDevice}=="0409"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{idVendor}=="1d6b"
ATTRS{product}=="DWC OTG Controller"
ATTRS{speed}=="480"
ATTRS{authorized_default}=="1"
ATTRS{interface_authorized_default}=="1"
ATTRS{removable}=="unknown"
ATTRS{ltm_capable}=="no"
ATTRS{serial}=="3f980000.usb"
ATTRS{bNumConfigurations}=="1"
ATTRS{busnum}=="1"
ATTRS{authorized}=="1"
ATTRS{quirks}=="0x0"
ATTRS{configuration}==""
ATTRS{devpath}=="0"
ATTRS{bDeviceProtocol}=="01"
ATTRS{bNumInterfaces}==" 1"

looking at parent device '/devices/platform/soc/3f980000.usb':
KERNELS=="3f980000.usb"
SUBSYSTEMS=="platform"
DRIVERS=="dwc_otg"
ATTRS{wr_reg_test}=="Time to write GNPTXFSIZ reg 10000000 times: 540 msecs (54 jiffies)"
ATTRS{grxfsiz}=="GRXFSIZ = 0x00000306"
ATTRS{srpcapable}=="SRPCapable = 0x1"
ATTRS{buspower}=="Bus Power = 0x1"
ATTRS{bussuspend}=="Bus Suspend = 0x0"
ATTRS{hptxfsiz}=="HPTXFSIZ = 0x02000406"
ATTRS{hnp}=="HstNegScs = 0x0"
ATTRS{mode}=="Mode = 0x1"
ATTRS{mode_ch_tim_en}=="Mode Change Ready Timer Enable = 0x0"
ATTRS{hsic_connect}=="HSIC Connect = 0x1"
ATTRS{gsnpsid}=="GSNPSID = 0x4f54280a"
ATTRS{driver_override}=="(null)"
ATTRS{hcd_frrem}=="HCD Dump Frame Remaining"
ATTRS{gotgctl}=="GOTGCTL = 0x001c0001"
ATTRS{gpvndctl}=="GPVNDCTL = 0x00000000"
ATTRS{hnpcapable}=="HNPCapable = 0x1"
ATTRS{spramdump}=="SPRAM Dump"
ATTRS{regoffset}=="0xffffffff"
ATTRS{gnptxfsiz}=="GNPTXFSIZ = 0x01000306"
ATTRS{guid}=="GUID = 0x2708a000"
ATTRS{regdump}=="Register Dump"
ATTRS{hprt0}=="HPRT0 = 0x00001405"
ATTRS{hcddump}=="HCD Dump"
ATTRS{rem_wakeup_pwrdn}==""
ATTRS{regvalue}=="invalid offset"
ATTRS{gusbcfg}=="GUSBCFG = 0x20001700"
ATTRS{fr_interval}=="Frame Interval = 0x1d4b"
ATTRS{busconnected}=="Bus Connected = 0x1"
ATTRS{remote_wakeup}=="Remote Wakeup Sig = 0 Enabled = 0 LPM Remote Wakeup = 0"
ATTRS{devspeed}=="Device Speed = 0x0"
ATTRS{rd_reg_test}=="Time to read GNPTXFSIZ reg 10000000 times: 1500 msecs (150 jiffies)"
ATTRS{enumspeed}=="Device Enumeration Speed = 0x1"
ATTRS{inv_sel_hsic}=="Invert Select HSIC = 0x0"
ATTRS{ggpio}=="GGPIO = 0x00000000"
ATTRS{srp}=="SesReqScs = 0x1"

looking at parent device '/devices/platform/soc':
KERNELS=="soc"
SUBSYSTEMS=="platform"
DRIVERS==""
ATTRS{driver_override}=="(null)"

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

$ udevadm monitor --property

KERNEL[50982.358011] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/bsg/0:0:0:0 (bsg)
ACTION=remove
DEVNAME=/dev/bsg/0:0:0:0
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/bsg/0:0:0:0
MAJOR=251
MINOR=0
SEQNUM=1095
SUBSYSTEM=bsg

KERNEL[50982.359131] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_generic/sg0 (scsi_generic)
ACTION=remove
DEVNAME=/dev/sg0
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_generic/sg0
MAJOR=21
MINOR=0
SEQNUM=1096
SUBSYSTEM=scsi_generic

KERNEL[50982.359731] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_device/0:0:0:0 (scsi_device)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_device/0:0:0:0
SEQNUM=1097
SUBSYSTEM=scsi_device

KERNEL[50982.361349] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0 (scsi_disk)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0
SEQNUM=1098
SUBSYSTEM=scsi_disk

KERNEL[50982.367606] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1 (block)
ACTION=remove
DEVNAME=/dev/sda1
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1
DEVTYPE=partition
MAJOR=8
MINOR=1
PARTN=1
SEQNUM=1099
SUBSYSTEM=block

KERNEL[50982.369279] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda (block)
ACTION=remove
DEVNAME=/dev/sda
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda
DEVTYPE=disk
MAJOR=8
MINOR=0
SEQNUM=1100
SUBSYSTEM=block

KERNEL[50982.370139] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0 (scsi)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0
DEVTYPE=scsi_device
MODALIAS=scsi:t-0x00
SEQNUM=1101
SUBSYSTEM=scsi

KERNEL[50982.410910] remove   /devices/virtual/bdi/8:0 (bdi)
ACTION=remove
DEVPATH=/devices/virtual/bdi/8:0
SEQNUM=1102
SUBSYSTEM=bdi

KERNEL[50982.411476] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0 (scsi)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0
DEVTYPE=scsi_target
SEQNUM=1103
SUBSYSTEM=scsi

KERNEL[50982.412387] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/scsi_host/host0 (scsi_host)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/scsi_host/host0
SEQNUM=1104
SUBSYSTEM=scsi_host

KERNEL[50982.414188] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0 (scsi)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0
DEVTYPE=scsi_host
SEQNUM=1105
SUBSYSTEM=scsi

KERNEL[50982.415487] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0
DEVTYPE=usb_interface
INTERFACE=8/6/80
MODALIAS=usb:v1058p10A2d1033dc00dsc00dp00ic08isc06ip50in00
PRODUCT=1058/10a2/1033
SEQNUM=1106
SUBSYSTEM=usb
TYPE=0/0/0

KERNEL[50982.419788] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 (usb)
ACTION=remove
BUSNUM=001
DEVNAME=/dev/bus/usb/001/007
DEVNUM=007
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2
DEVTYPE=usb_device
MAJOR=189
MINOR=6
PRODUCT=1058/10a2/1033
SEQNUM=1107
SUBSYSTEM=usb
TYPE=0/0/0

UDEV  [50982.973557] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/bsg/0:0:0:0 (bsg)
ACTION=remove
DEVNAME=/dev/bsg/0:0:0:0
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/bsg/0:0:0:0
MAJOR=251
MINOR=0
SEQNUM=1095
SUBSYSTEM=bsg
USEC_INITIALIZED=982359004

UDEV  [50982.999940] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_device/0:0:0:0 (scsi_device)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_device/0:0:0:0
SEQNUM=1097
SUBSYSTEM=scsi_device
USEC_INITIALIZED=982362751

UDEV  [50983.095057] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1 (block)
ACTION=remove
DEVLINKS=/dev/disk/by-id/usb-WD_Elements_10A2_575831314541323038393032-0:0-part1 /dev/disk/by-label/Steven /dev/disk/by-path/platform-3f980000.usb-usb-0:1.2:1.0-scsi-0:0:0:0-part1 /dev/disk/by-uuid/21741F4F6C4915E1
DEVNAME=/dev/sda1
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1
DEVTYPE=partition
ID_BUS=usb
ID_FS_LABEL=Steven
ID_FS_LABEL_ENC=Steven
ID_FS_TYPE=ntfs
ID_FS_USAGE=filesystem
ID_FS_UUID=21741F4F6C4915E1
ID_FS_UUID_ENC=21741F4F6C4915E1
ID_INSTANCE=0:0
ID_MODEL=Elements_10A2
ID_MODEL_ENC=Elements\x2010A2\x20\x20\x20
ID_MODEL_ID=10a2
ID_PART_ENTRY_DISK=8:0
ID_PART_ENTRY_NUMBER=1
ID_PART_ENTRY_OFFSET=2048
ID_PART_ENTRY_SCHEME=dos
ID_PART_ENTRY_SIZE=1953456128
ID_PART_ENTRY_TYPE=0x7
ID_PART_ENTRY_UUID=00023f15-01
ID_PART_TABLE_TYPE=dos
ID_PART_TABLE_UUID=00023f15
ID_PATH=platform-3f980000.usb-usb-0:1.2:1.0-scsi-0:0:0:0
ID_PATH_TAG=platform-3f980000_usb-usb-0_1_2_1_0-scsi-0_0_0_0
ID_REVISION=1033
ID_SERIAL=WD_Elements_10A2_575831314541323038393032-0:0
ID_SERIAL_SHORT=575831314541323038393032
ID_TYPE=disk
ID_USB_DRIVER=usb-storage
ID_USB_INTERFACES=:080650:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=WD
ID_VENDOR_ENC=WD\x20\x20\x20\x20\x20\x20
ID_VENDOR_ID=1058
MAJOR=8
MINOR=1
PARTN=1
SEQNUM=1099
SUBSYSTEM=block
TAGS=:systemd:
USEC_INITIALIZED=8036767

UDEV  [50983.126799] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0 (scsi_disk)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0
SEQNUM=1098
SUBSYSTEM=scsi_disk
USEC_INITIALIZED=982364537

UDEV  [50983.136895] remove   /devices/virtual/bdi/8:0 (bdi)
ACTION=remove
DEVPATH=/devices/virtual/bdi/8:0
SEQNUM=1102
SUBSYSTEM=bdi
USEC_INITIALIZED=982411342

UDEV  [50983.138940] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_generic/sg0 (scsi_generic)
ACTION=remove
DEVNAME=/dev/sg0
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_generic/sg0
MAJOR=21
MINOR=0
SEQNUM=1096
SUBSYSTEM=scsi_generic
USEC_INITIALIZED=982360886

KERNEL[50983.194516] remove   /devices/virtual/bdi/8:1-fuseblk (bdi)
ACTION=remove
DEVPATH=/devices/virtual/bdi/8:1-fuseblk
SEQNUM=1108
SUBSYSTEM=bdi

UDEV  [50983.204265] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/scsi_host/host0 (scsi_host)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/scsi_host/host0
SEQNUM=1104
SUBSYSTEM=scsi_host
USEC_INITIALIZED=982413320

UDEV  [50983.643690] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda (block)
ACTION=remove
DEVLINKS=/dev/disk/by-id/usb-WD_Elements_10A2_575831314541323038393032-0:0 /dev/disk/by-path/platform-3f980000.usb-usb-0:1.2:1.0-scsi-0:0:0:0
DEVNAME=/dev/sda
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda
DEVTYPE=disk
ID_BUS=usb
ID_INSTANCE=0:0
ID_MODEL=Elements_10A2
ID_MODEL_ENC=Elements\x2010A2\x20\x20\x20
ID_MODEL_ID=10a2
ID_PART_TABLE_TYPE=dos
ID_PART_TABLE_UUID=00023f15
ID_PATH=platform-3f980000.usb-usb-0:1.2:1.0-scsi-0:0:0:0
ID_PATH_TAG=platform-3f980000_usb-usb-0_1_2_1_0-scsi-0_0_0_0
ID_REVISION=1033
ID_SERIAL=WD_Elements_10A2_575831314541323038393032-0:0
ID_SERIAL_SHORT=575831314541323038393032
ID_TYPE=disk
ID_USB_DRIVER=usb-storage
ID_USB_INTERFACES=:080650:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=WD
ID_VENDOR_ENC=WD\x20\x20\x20\x20\x20\x20
ID_VENDOR_ID=1058
MAJOR=8
MINOR=0
SEQNUM=1100
SUBSYSTEM=block
TAGS=:systemd:
USEC_INITIALIZED=748036370

UDEV  [50983.733473] remove   /devices/virtual/bdi/8:1-fuseblk (bdi)
ACTION=remove
DEVPATH=/devices/virtual/bdi/8:1-fuseblk
SEQNUM=1108
SUBSYSTEM=bdi
USEC_INITIALIZED=3192262

UDEV  [50984.141379] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0 (scsi)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0
DEVTYPE=scsi_device
MODALIAS=scsi:t-0x00
SEQNUM=1101
SUBSYSTEM=scsi
USEC_INITIALIZED=2371212

UDEV  [50984.629455] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0 (scsi)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0
DEVTYPE=scsi_target
SEQNUM=1103
SUBSYSTEM=scsi
USEC_INITIALIZED=2413053

UDEV  [50985.087418] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0 (scsi)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0
DEVTYPE=scsi_host
SEQNUM=1105
SUBSYSTEM=scsi
USEC_INITIALIZED=2415484

UDEV  [50985.618300] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
ACTION=remove
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0
DEVTYPE=usb_interface
ID_MODEL_FROM_DATABASE=Elements SE Portable (WDBPCK)
ID_VENDOR_FROM_DATABASE=Western Digital Technologies, Inc.
INTERFACE=8/6/80
MODALIAS=usb:v1058p10A2d1033dc00dsc00dp00ic08isc06ip50in00
PRODUCT=1058/10a2/1033
SEQNUM=1106
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=5647475

UDEV  [50986.078354] remove   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 (usb)
ACTION=remove
BUSNUM=001
DEVNAME=/dev/bus/usb/001/007
DEVNUM=007
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2
DEVTYPE=usb_device
ID_BUS=usb
ID_MODEL=Elements_10A2
ID_MODEL_ENC=Elements\x2010A2
ID_MODEL_FROM_DATABASE=Elements SE Portable (WDBPCK)
ID_MODEL_ID=10a2
ID_REVISION=1033
ID_SERIAL=Western_Digital_Elements_10A2_575831314541323038393032
ID_SERIAL_SHORT=575831314541323038393032
ID_USB_INTERFACES=:080650:
ID_VENDOR=Western_Digital
ID_VENDOR_ENC=Western\x20Digital
ID_VENDOR_FROM_DATABASE=Western Digital Technologies, Inc.
ID_VENDOR_ID=1058
MAJOR=189
MINOR=6
PRODUCT=1058/10a2/1033
SEQNUM=1107
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=745644833
  • Try putting everything on a single line instead of several lines (unless this is a formatting accident). I'm actually not sure if that is required, but it's worth a shot. – dirkt May 30 '17 at 14:29
  • Please post the answer to this question as an ANSWER, not as an edit of the QUESTION. – Celada May 30 '17 at 17:17
  • Oh yeah sorry, rookie mistake – Mr. Steve May 30 '17 at 19:59
1

Thanks to dirkt for finding the solution:

Indeed the rules must be on a single line. This fixes the repeated script calls (if a unique variable is used) and now the script is only called when the device is disconnected. For me the following configuration did the trick:

ACTION=="remove", ENV{ID_FS_UUID}=="21741F4F6C4915E1", RUN+="/home/pi/HDD_removed.sh"
1

As others have already identified, each line in your snippets is a separate rule, either doing nothing (lines with only ==) or running a command on every udev event (lines with only = or +=). You need to put the whole rule on a single logical line.

You can split lines in udev rules, but you need to put a backslash at the end of a line if the rule continues on the next line. In other words, a logical line can contain the two-character sequence backslash-newline, which is ignored.

ACTION=="remove", \
ENV{ID_MODEL}=="Elements_10A2", \
RUN+="/home/pi/HDD_removed.sh"

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.