简单的 udev 规则不起作用

简单的 udev 规则不起作用

在 Ubuntu Server 16.04.1 上

我想知道 udev 正在检测哪些磁带设备。

$ cat /etc/udev/rules.d/90-persistent-tape4.rules
SUBSYSTEM="scsi_tape", RUN+="/usr/local/bin/testudev"

剧本:

$ cat /usr/local/bin/testudev
#!/bin/bash

echo "Called by udev" >> /tmp/testenv
env >> /tmp/testenv
echo "Vendor id is $ID_VENDOR" >> /tmp/testenv
echo "Serial id is $ID_SERIAL" >> /tmp/testenv

它正在工作:

$ ll /usr/local/bin/testudev
-rwxr-xr-x 1 root root 165 Feb 16 07:59 /usr/local/bin/testudev*

$ /usr/local/bin/testudev
$ cat /tmp/testenv
Called by udev
XDG_SESSION_ID=1
SHELL=/bin/bash
TERM=xterm-256color
SSH_CLIENT=192.168.10.4 37916 22
SSH_TTY=/dev/pts/0
USER=tessio
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
PATH=/home/tessio/bin:/home/tessio/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
MAIL=/var/mail/tessio
PWD=/tmp
LANG=en_US.UTF-8
HOME=/home/tessio
SHLVL=2
LANGUAGE=en_US:en
LOGNAME=tessio
SSH_CONNECTION=192.168.10.4 37916 192.168.10.49 22
LESSOPEN=| /usr/bin/lesspipe %s
XDG_RUNTIME_DIR=/run/user/1000
LESSCLOSE=/usr/bin/lesspipe %s %s
_=/usr/bin/env
Vendor id is 
Serial id is 

但是该规则没有被udev触发:

$ rm /tmp/testenv

$ sudo udevadm trigger -v -s scsi_tape
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-2/target1:0:0/1:0:0:0/scsi_tape/nst0
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-2/target1:0:0/1:0:0:0/scsi_tape/nst0a
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-2/target1:0:0/1:0:0:0/scsi_tape/nst0l
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-2/target1:0:0/1:0:0:0/scsi_tape/nst0m
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-2/target1:0:0/1:0:0:0/scsi_tape/st0
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-2/target1:0:0/1:0:0:0/scsi_tape/st0a
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-2/target1:0:0/1:0:0:0/scsi_tape/st0l
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-2/target1:0:0/1:0:0:0/scsi_tape/st0m
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-3/target1:0:1/1:0:1:0/scsi_tape/nst1
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-3/target1:0:1/1:0:1:0/scsi_tape/nst1a
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-3/target1:0:1/1:0:1:0/scsi_tape/nst1l
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-3/target1:0:1/1:0:1:0/scsi_tape/nst1m
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-3/target1:0:1/1:0:1:0/scsi_tape/st1
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-3/target1:0:1/1:0:1:0/scsi_tape/st1a
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-3/target1:0:1/1:0:1:0/scsi_tape/st1l
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-3/target1:0:1/1:0:1:0/scsi_tape/st1m
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-2/target2:0:0/2:0:0:0/scsi_tape/nst2
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-2/target2:0:0/2:0:0:0/scsi_tape/nst2a
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-2/target2:0:0/2:0:0:0/scsi_tape/nst2l
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-2/target2:0:0/2:0:0:0/scsi_tape/nst2m
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-2/target2:0:0/2:0:0:0/scsi_tape/st2
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-2/target2:0:0/2:0:0:0/scsi_tape/st2a
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-2/target2:0:0/2:0:0:0/scsi_tape/st2l
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-2/target2:0:0/2:0:0:0/scsi_tape/st2m
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-3/target2:0:1/2:0:1:0/scsi_tape/nst3
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-3/target2:0:1/2:0:1:0/scsi_tape/nst3a
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-3/target2:0:1/2:0:1:0/scsi_tape/nst3l
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-3/target2:0:1/2:0:1:0/scsi_tape/nst3m
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-3/target2:0:1/2:0:1:0/scsi_tape/st3
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-3/target2:0:1/2:0:1:0/scsi_tape/st3a
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-3/target2:0:1/2:0:1:0/scsi_tape/st3l
/sys/devices/pci0000:00/0000:00:07.0/0000:06:00.1/host2/rport-2:0-3/target2:0:1/2:0:1:0/scsi_tape/st3m

$ cat /tmp/testenv
cat: /tmp/testenv: No such file or directory

应该触发该脚本的设备之一:

$ udevadm info --name=/dev/st0 --query=all
P: /devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-2/target1:0:0/1:0:0:0/scsi_tape/st0
N: st0
S: tape/by-id/scsi-35001438013e92f95
S: tape/by-path/pci-0000:06:00.0-fc-0x5001438013e92f96-lun-0
E: DEVLINKS=/dev/tape/by-id/scsi-35001438013e92f95 /dev/tape/by-path/pci-0000:06:00.0-fc-0x5001438013e92f96-lun-0
E: DEVNAME=/dev/st0
E: DEVPATH=/devices/pci0000:00/0000:00:07.0/0000:06:00.0/host1/rport-1:0-2/target1:0:0/1:0:0:0/scsi_tape/st0
E: ID_BUS=scsi
E: ID_MODEL=Ultrium_4-SCSI
E: ID_MODEL_ENC=Ultrium\x204-SCSI\x20\x20
E: ID_PATH=pci-0000:06:00.0-fc-0x5001438013e92f96-lun-0
E: ID_PATH_TAG=pci-0000_06_00_0-fc-0x5001438013e92f96-lun-0
E: ID_REVISION=H68W
E: ID_SCSI=1
E: ID_SCSI_SERIAL=HU1104EUDW
E: ID_SERIAL=35001438013e92f95
E: ID_SERIAL_SHORT=5001438013e92f95
E: ID_TARGET_PORT=0
E: ID_TYPE=tape
E: ID_VENDOR=HP
E: ID_VENDOR_ENC=HP\x20\x20\x20\x20\x20\x20
E: ID_WWN=0x5001438013e92f95
E: ID_WWN_WITH_EXTENSION=0x5001438013e92f95
E: MAJOR=9
E: MINOR=0
E: SUBSYSTEM=scsi_tape
E: USEC_INITIALIZED=63850259166

答案1

愚蠢的问题......

SUBSYSTEM="scsi_tape", RUN+="/usr/local/bin/testudev"

应该:

SUBSYSTEM=="scsi_tape", RUN+="/usr/local/bin/testudev"

相关内容