0

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 ?

user128712
  • 2,372

1 Answers1

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