1

I'm trying to make a script run automatically when I dock or undock my laptop. I have this simple test script I want to run:

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

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

Permissions:

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

Udev Rule:

$ 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"

Test Run:

$ 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.

I've reloaded the rules:

$ sudo udevadm control --reload

But whenever I actually undock no file is created.

1
  • Could you add log of udevadm monitor -u when docking & when undocking ?
    – user.dz
    Aug 6, 2019 at 18:40

0

You must log in to answer this question.

Browse other questions tagged .