LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   udev does not run program on remove (http://www.linuxquestions.org/questions/slackware-14/udev-does-not-run-program-on-remove-494378/)

uselpa 10-21-2006 11:18 AM

udev does not run program on remove
 
I am playing around with udev and automounting.
I put the following rule in /etc/udev/rules:
Code:

BUS=="scsi",DRIVER=="sd",SYSFS{model}=="USB Disk        ",SYSFS{vendor}=="Generic ",SYMLINK+="_usbdisk%n",RUN+="/etc/udev/scripts/automount"
which creates the symlink as expected. The "automount" script is as follows:
Code:

#!/bin/bash
printenv >> /tmp/udev.log
echo >> /tmp/udev.log

which executes as expected for adds, but never for removes, although udevmonitor shows that removes are intercepted:
Quote:

UDEV [1161443405.906373] add@/block/sdb/sdb1
and later
Quote:

UDEV [1161443416.496382] remove@/block/sdb/sdb1
.
So what do I have to do in order to have my script run at removal as well?

/bin/bash 10-22-2006 05:01 AM

I think you need an ACTION="remove" that matches your other rule. I've not done this but I think thats how it's done.

ACTION="remove", SYSFS{model}=="USB Disk ", SYSFS{vendor}=="Generic ", RUN+="/etc/udev/scripts/automount"

uselpa 10-22-2006 05:24 AM

I've changed the rules to this:
Quote:

ACTION=="add",BUS=="scsi",DRIVER=="sd",SYSFS{model}=="USB Disk ",SYSFS{vendor}=="Generic ",SYMLINK+="_usbdisk%n",RUN+="/etc/udev/scripts/automount add"
ACTION=="remove",BUS=="scsi",DRIVER=="sd",SYSFS{model}=="USB Disk ",SYSFS{vendor}=="Generic ",RUN+="/etc/udev/scripts/automount remove"
and the script to
Quote:

#!/bin/bash
echo "parameter = $1" >> /tmp/udev.log
printenv >> /tmp/udev.log
echo >> /tmp/udev.log
The events get caught properly:
Quote:

root@slackw:~$ udevmonitor
udevmonitor prints the received event from the kernel [UEVENT]
and the event which udev sends out after rule processing [UDEV]

UEVENT[1161508773.336420] add@/devices/pci0000:00/0000:00:03.3/usb1/1-4
UEVENT[1161508773.336474] add@/devices/pci0000:00/0000:00:03.3/usb1/1-4/1-4:1.0
UEVENT[1161508773.336484] add@/class/scsi_host/host4
UEVENT[1161508773.336493] add@/class/usb_device/usbdev1.6
UDEV [1161508773.337278] add@/devices/pci0000:00/0000:00:03.3/usb1/1-4
UDEV [1161508773.378090] add@/devices/pci0000:00/0000:00:03.3/usb1/1-4/1-4:1.0
UDEV [1161508773.379450] add@/class/scsi_host/host4
UDEV [1161508773.386399] add@/class/usb_device/usbdev1.6
UEVENT[1161508778.336995] add@/devices/pci0000:00/0000:00:03.3/usb1/1-4/1-4:1.0/host4/target4:0:0/4:0:0:0
UEVENT[1161508778.337283] add@/class/scsi_disk/4:0:0:0
UEVENT[1161508778.488173] add@/block/sda
UEVENT[1161508778.488200] add@/block/sda/sda1
UEVENT[1161508778.488209] add@/class/scsi_device/4:0:0:0
UEVENT[1161508778.488218] add@/class/scsi_generic/sg0
UDEV [1161508778.506964] add@/devices/pci0000:00/0000:00:03.3/usb1/1-4/1-4:1.0/host4/target4:0:0/4:0:0:0
UDEV [1161508778.507682] add@/class/scsi_disk/4:0:0:0
UDEV [1161508778.532756] add@/block/sda
UDEV [1161508778.568888] add@/class/scsi_device/4:0:0:0
UDEV [1161508778.571559] add@/class/scsi_generic/sg0
UDEV [1161508778.755430] add@/block/sda/sda1
UEVENT[1161508786.825967] remove@/class/scsi_generic/sg0
UEVENT[1161508786.826001] remove@/class/scsi_device/4:0:0:0
UEVENT[1161508786.826011] remove@/class/scsi_disk/4:0:0:0
UEVENT[1161508786.826020] remove@/block/sda/sda1
UEVENT[1161508786.826030] remove@/block/sda
UEVENT[1161508786.826039] remove@/devices/pci0000:00/0000:00:03.3/usb1/1-4/1-4:1.0/host4/target4:0:0/4:0:0:0
UEVENT[1161508786.826049] remove@/class/scsi_host/host4
UEVENT[1161508786.826058] remove@/devices/pci0000:00/0000:00:03.3/usb1/1-4/1-4:1.0
UEVENT[1161508786.826068] remove@/class/usb_device/usbdev1.6
UEVENT[1161508786.826077] remove@/devices/pci0000:00/0000:00:03.3/usb1/1-4
UDEV [1161508786.827266] remove@/class/scsi_generic/sg0
UDEV [1161508786.828172] remove@/class/scsi_device/4:0:0:0
UDEV [1161508786.829055] remove@/class/scsi_disk/4:0:0:0
UDEV [1161508786.830149] remove@/block/sda/sda1
UDEV [1161508786.831270] remove@/devices/pci0000:00/0000:00:03.3/usb1/1-4/1-4:1.0/host4/target4:0:0/4:0:0:0
UDEV [1161508786.832502] remove@/class/scsi_host/host4
UDEV [1161508786.833552] remove@/class/usb_device/usbdev1.6
UDEV [1161508786.834596] remove@/block/sda
UDEV [1161508786.835616] remove@/devices/pci0000:00/0000:00:03.3/usb1/1-4/1-4:1.0
UDEV [1161508786.836746] remove@/devices/pci0000:00/0000:00:03.3/usb1/1-4
Still:
Quote:

root@slackw:/tmp$ grep parameter udev.log
parameter = add
parameter = add
parameter = add


All times are GMT -5. The time now is 04:44 AM.