Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm interested in running an rsync script whenever any new volume is mounted on my Debian box. What are some potential triggers / strategies for listening for a new volume mount?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You can create a new rule to /etc/udev/rules.d/. First read the file /etc/udev/rules.d/README. In the new rule file, add something like

KERNEL=="sd?1",ACTION=="mount",RUN+="/path/to/script.sh"

(I did not try the above line, try your own rules.)

Note that the script will be run as root. You might want to use su to change that.

Using ACTION=="add" would require script.sh first to mount the volume.

share|improve this answer
1  
This catches the case when the volume is attached, but not the mount. A mount might not necessarily occur when it's attached. –  Marco Sep 6 '12 at 12:16
    
Marco, correct. I edited the ACTION from add to mount. I still cannot test the rule, so please be careful with that. Also SUBSYSTEM=="block"might be more useful than KERNEL. –  Jari Laamanen Sep 6 '12 at 12:47

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.