Eu pego um evento de CD-ROM baseado nesta regra:
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'"
quando o CD-ROM é conectado / removido, ele gera o mesmo evento 3 vezes seguidas para 1 ação. Como posso modificar a regra para que ela possa distinguir a inserção e a ejeção da unidade?
os próprios eventos de CD-ROM são assim:
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