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 have a USB key that contains my keepass2 password database and I'd like to perform some actions when it is plugged into my computer, namely:

  • Auto-mount it to some specific location
  • When the mounting is done properly, launching keepass2 on the password database file

Simple tasks I guess, but I can't find how to do that.

I'm using Ubuntu 12.10, and it auto-mounts the device as a "media usb-key" and tries to open the images on it (even though there are none).

What is the best way to do that and to disable the ubuntu auto-mounting (so it doesn't conflict) ?

share|improve this question

1 Answer 1

You can do this with udev, you must write rules in separate file and put them to /etc/udev/rules.d

For example this rule describes udev to run /path/to/mount/script when usb is mounted and /path/to/umount/script when umounted.

SUBSYSTEMS=="usb", ACTION=="add", KERNEL=="sd[a-z]1", RUN+="/path/to/mount/script", OPTIONS="last_rule"
SUBSYSTEMS=="usb", ACTION=="remove", KERNEL=="sd[a-z]1", RUN+="/path/to/umount/script"

Here you can read complete manual.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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