Is there a way to run a script when a particular USB device is mounted?
I keep my videos on a separate USB and would like to run a script that would mount the video folder on the USB device to the one in the home folder.
mountusb
Is there a way to run a script when a particular USB device is mounted?
I keep my videos on a separate USB and would like to run a script that would mount the video folder on the USB device to the one in the home folder.
Best Answer
There's much nicer solution with systemd now. You create a service which depends and is wanted by you media e.g.:
/etc/systemd/system/your.service
Then you have to start/enable the service:
After mount, systemd fires your trigger script. The advantage over udev rule is that the script really fires after mount, not after adding system device.
Use case: I have an encrypted partition which I want to backup automatically. After adding the device I have to type in the password. If I hooked the backup script to udev, the script attempts to run at the time when I'm typing password, which will fail.
Resource: Scripting with udev
Note: You can find your device unit with: