1

I catch a CD-ROM event based on this rule:

ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sr[0-9]*", ENV{DEVTYPE}=="disk", RUN+="/bin/bash -c '/bin/echo cdrom1-%k-%E{ACTION}-%E{ID_CDROM_MEDIA_BD}>> /tmp/cdrom.event'"

when the CD-ROM is connected/removed it generates the same event 3 times in a row for 1 action. How can I modify the rule so it can distinguish inserting and ejecting the drive?

the CD-ROM events themselves look like this:

UDEV  [1499340281.456105] change   
/devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0 (scsi)
UDEV_LOG=3
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0
SUBSYSTEM=scsi
SDEV_MEDIA_CHANGE=1
DEVTYPE=scsi_device
DRIVER=sr
MODALIAS=scsi:t-0x05
SEQNUM=2243

UDEV  [1499340281.587415] change       /devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sr0 (block)
UDEV_LOG=3
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sr0
SUBSYSTEM=block
DEVNAME=/dev/sr0
DEVTYPE=disk
SEQNUM=2244
MPATH_SBIN_PATH=/sbin
ID_CDROM=1
ID_CDROM_CD_R=1
ID_CDROM_CD_RW=1
ID_CDROM_DVD=1
ID_CDROM_DVD_R=1
ID_CDROM_DVD_RAM=1
ID_SCSI=1
ID_VENDOR=hp
ID_VENDOR_ENC=hp\x20\x20\x20\x20\x20\x20
ID_MODEL=DVD-RAM_GHC0N
ID_MODEL_ENC=DVD-RAM\x20GHC0N\x20\x20\x20
ID_REVISION=RL05
ID_TYPE=cd
ID_BUS=scsi
ID_PATH=pci-0000:00:1f.2-scsi-2:0:0:0
LVM_SBIN_PATH=/sbin
ACL_MANAGE=1
GENERATED=1
UDISKS_PRESENTATION_NOPOLICY=0
MAJOR=11
MINOR=0
DEVLINKS=/dev/block/11:0 /dev/scd0 /dev/disk/by-path/pci-0000:00:1f.2-scsi-    2:0:0:0 /dev/cdrom /dev/cdrw /dev/dvd /dev/dvdrw

Your Answer

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

Browse other questions tagged or ask your own question.