I want my usb to run a command or a script --like autorun-- when it is plugged in. I've also searching and found out that autorun was not present because of some security reason(s). How do you run a command after a specific type of USB is plugged in ?
Asked
Active
Viewed 2,962 times
0
-
@RaduRădeanu I don't think the answer to that question is very helpful. Instead, see this one: How to run a script when a specific flash-drive is mounted? (answer does also apply for just plugging in). – gertvdijk Jun 30 '13 at 18:40
-
@gertvdijk There are many duplicates in this sense. That was first that I find it. – Radu Rădeanu Jun 30 '13 at 18:52
1 Answers
3
Place your script in /usr/local/bin (otherwise this sometimes refuses to work). Then create file /etc/udev/rules.d/99-usb.rules. In it, place the line like
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z]1", ATTRS{vendor}=="SanDisk ", RUN+="/usr/local/bin/backup.sh"
Adapt to your needs. Generally, it works, but , however, i've never tried it on Ubuntu.
Also, don't forget to reload udev to take your new file into account with:
udevadm control --reload

Barafu Albino
- 6,541