我根据以下规则捕获 CD-ROM 事件:
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'"
当连接/移除 CD-ROM 时,对于 1 个操作,它会连续 3 次生成相同的事件。如何修改规则以区分插入和弹出驱动器?
CD-ROM 事件本身如下所示:
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