udev 脚本未运行,在测试中有效

udev 脚本未运行,在测试中有效

我正在尝试让脚本在笔记本电脑对接或断开对接时自动运行。我有一个简单的测试脚本要运行:

$ cat /usr/local/bin/undock.sh 
#!/bin/sh

/usr/bin/touch /tmp/testFile.txt

权限:

$ ls -l /usr/local/bin/undock.sh
-rwxr-xr-x 1 root root 44 Jul  1 09:06 /usr/local/bin/undock.sh

Udev 规则:

$ cat /etc/udev/rules.d/80-thunder-dock.rules
ACTION=="remove", ATTRS{vendor}=="0xd4", ATTR{device}=="0xb054", RUN+="/bin/sh /usr/local/bin/undock.sh"

测试运行:

$ udevadm test --action="remove" /devices/pci0000:00/0000:00:1b.0/0000:02:00.0/0000:03:00.0/0000:04:00.0/domain0/0-0/0-1/0-301
calling: test
version 229
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

=== trie on-disk ===
tool version:          229
file size:         7064125 bytes
header size             80 bytes
strings            1764285 bytes
nodes              5299760 bytes
Load module index
timestamp of '/etc/systemd/network' changed
timestamp of '/lib/systemd/network' changed
Parsed configuration file /lib/systemd/network/99-default.link
Created link configuration context.
timestamp of '/etc/udev/rules.d' changed
Reading rules file: /lib/udev/rules.d/39-usbmuxd.rules
...
Reading rules file: /etc/udev/rules.d/80-thunder-dock.rule
...
Reading rules file: /lib/udev/rules.d/99-systemd.rules
rules contain 393216 bytes tokens (32768 * 12 bytes), 35657 bytes strings
26722 strings (221858 bytes), 23118 de-duplicated (189806 bytes), 3605 trie nodes used
value '[dmi/id]sys_vendor' is 'Dell Inc.'
value '[dmi/id]sys_vendor' is 'Dell Inc.'
RUN '/bin/sh /usr/local/bin/undock.sh' /etc/udev/rules.d/80-thunder-dock.rules:1
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1b.0/0000:02:00.0/0000:03:00.0/0000:04:00.0/domain0/0-0/0-1/0-301
DEVTYPE=thunderbolt_device
SUBSYSTEM=thunderbolt
run: '/bin/sh /usr/local/bin/undock.sh'
Unload module index
Unloaded link configuration context.

我已重新加载规则:

$ sudo udevadm control --reload

但每当我真正取消停靠时,都不会创建任何文件。

相关内容