Is there any way to detect when a USB Wi-Fi adapter is physically disconnected from the Pi, and run a command when that happens? I'm using the Raspberry Pi 1, model B+, and the adapter is connected to the bottom right USB port. It's the Ralink RT5370 adapter, if it helps.
Asked
Active
Viewed 88 times
1 Answers
3
Assuming you don't have any network equipment other that the WIFI dongle that you could unplug, you could simply write
SUBSYSTEM=="net", ACTION=="remove", RUN+="/path/to/command"
into a file named /etc/udev/rules.d/my_custom.rules
. Note that you need to specify the full path to your command, since it will be executed directly, without using a shell.

Dmitry Grigoryev
- 27,928
- 6
- 53
- 144
shutdown
). If you mean "disconnected from the network" also yes, but the methodology would be unrelated. – goldilocks May 22 '16 at 18:11