Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 ?

share|improve this question

marked as duplicate by Radu Rădeanu, Jorge Castro, gertvdijk, Basharat Sialvi, Eric Carvalho Jul 1 '13 at 2:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
@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 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.