我写了一个像这样的udev规则:
SUBSYSTEM=="usb",ACTION=="add",RUN+="//root/usbmon/usb add %b" SUBSYSTEM=="usb",ACTION=="remove",RUN+="//root/usbmon/usb remove %b"
但问题是每次发送2封电子邮件.这意味着规则正在执行2次.这就是我在日志中得到的
Apr 26 14:52:00 Box2 sendEmail[3374]: Email was sent successfully! USB Added: Email sent to Box2@dmz.domain.com Using Udev Rule at 04-26-14-52-00. Apr 26 14:52:00 Box2 sendEmail[3394]: Email was sent successfully! USB Added: Email sent to Box2@dmz.domain.com Using Udev Rule at 04-26-14-52-00.
我不知道为什么它会执行2次以及如何阻止它一次工作?我已经确认问题是在udev结束但不知道如何解决它.当附加USB时,这是udev监视器的输出:
KERNEL[1335803018.283341] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4 (usb) KERNEL[1335803018.284456] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0 (usb) KERNEL[1335803018.284835] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6 (scsi) KERNEL[1335803018.284863] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/scsi_host/host6 (scsi_host) KERNEL[1335803023.524167] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0 (scsi) KERNEL[1335803023.524735] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0 (scsi) KERNEL[1335803023.525043] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/scsi_disk/6:0:0:0 (scsi_disk) KERNEL[1335803023.525154] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/scsi_device/6:0:0:0 (scsi_device) KERNEL[1335803023.525505] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/scsi_generic/sg6 (scsi_generic) KERNEL[1335803023.525792] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/bsg/6:0:0:0 (bsg) KERNEL[1335803023.526534] add /devices/virtual/bdi/8:80 (bdi) UDEV [1335803023.526895] add /devices/virtual/bdi/8:80 (bdi) KERNEL[1335803023.543043] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/block/sdf (block) KERNEL[1335803023.543166] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/block/sdf/sdf1 (block) UDEV [1335803028.541785] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4 (usb) UDEV [1335803038.850181] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0 (usb) UDEV [1335803038.850423] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6 (scsi) UDEV [1335803038.850541] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0 (scsi) UDEV [1335803038.850568] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/scsi_host/host6 (scsi_host) UDEV [1335803038.851736] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0 (scsi) UDEV [1335803038.851912] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/scsi_disk/6:0:0:0 (scsi_disk) UDEV [1335803038.861401] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/scsi_device/6:0:0:0 (scsi_device) UDEV [1335803038.862757] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/bsg/6:0:0:0 (bsg) UDEV [1335803038.863880] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/scsi_generic/sg6 (scsi_generic) UDEV [1335803039.002743] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/block/sdf (block) UDEV [1335803039.072845] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host6/target6:0:0/6:0:0:0/block/sdf/sdf1 (block)
现在上面的输出清楚地显示udev在10秒后再次连接设备,这是我再次收到电子邮件的时间(10秒后).当脚本不可执行时,我在日志文件中收到以下消息2次:
Apr 30 10:22:37 Box2 udevd-work[1990]: exec of program '/root/usbmon/usb' Failed Apr 30 10:22:37 Box2 udevd-work[1991]: exec of program '/root/usbmon/usb' Failed
现在我想知道我需要更改这些设置以使udev运行一次.我在2台服务器上验证了相同的东西. CentOS和ubuntu.