dosdroid
dosdroid

Reputation: 41

Run command after mount/unmout usb pen drive

I have Raspberry Pi (with Raspbian) and using it as DLNA/UPnP server and renderer. I run minidlna as DLNA server and i have some media files on USB.

I would like to automaticaly rebuild DLNA DB when drive is mounted and unmounted. This is done by command:

sudo service minidlna force-reload

Is threre any way how to autorun this command?

BTW I use "USBmount" package for automount USB drives.

Thanx

Upvotes: 4

Views: 5043

Answers (2)

danielenick89
danielenick89

Reputation: 101

You can do this using the tool usbmount. It has the possibility to add scripts that will be run on mount/umount events in /etc/usbmount/mount.d/ and /etc/usbmount/umount.d/.

Upvotes: 5

Pavel Stárek
Pavel Stárek

Reputation: 1039

Start by finding your device in lsusb. Note the ID (eg 12f5:a91a)

Create a new udev rules file in /etc/udev/rules.d/ eg /etc/udev/rules.d/100-my-mount.rules and write a new rule in there like this:

ACTION=="add", ATTRS{idVendor}=="12f5", ATTRS{idProduct}=="a91a", RUN+="/home/your_username/bin/my-mount-script.sh"

For unmounted device use ACTION=="remove" in rule and another script.

Upvotes: 2

Related Questions