I wrote the following udev rule to execute a script that rescans pci devices on connect of my thunderbolt dock:
ACTION=="add", SUBSYSTEM=="thunderbolt", ATTR{vendor}=="0x1b", ATTR{device}=="0xd", RUN+="/usr/local/scripts/pcirescan.sh"
And here is the script:
#!/bin/bash
# A script to rescan pci devices, run as root
sleep 10
echo 1 > /sys/bus/pci/rescan
if [ $? -eq 0 ]; then
echo "PCI devices successfully rescanned" > /home/mattkavs/pci-on-connect.log
else
echo "PCI devices rescan failed" > /home/mattkavs/pci-on-connect.log
fi
exit 0
The script runs on connect, as the test log file is indeed created. When run from the command line or via a systemd service at boot it works properly and my connected keyboard, mouse, ethernet all start working.
When executed via the udev rule, however, none of this works. My keyboard backlight does turn on but nothing else. Mouse and keyboard inputs not registered from connected devices, ethernet not recognized.
I’ve tried adding a sleep and repeating the echo command again within the script but that doesn’t work either, other than a second flash off and on of the keyboard backlight.
Any ideas why this isn’t working?