1

I want to setup notification whenever any network drive is mounted or unmounted. (Basically I want to run a custom script, whenever any network storage is mounted or unmounted). I think udev can do this, but I don't know how to write udev rule for such a task.

When I mount a network share using the following command:

sudo mount -t cifs -o username=user,password=pwd //ipaddr/sharename mountpoint

the filesystem is successfully mounted I can see the following sysfs entries were created:

/sys/class/bdi/cifs-<num>/ & /sys/devices/virtual/bdi/cifs-<num>

Can udev monitor such a change? If yes, how does the rule look like? Or is there some other method to do this?

Any help appreciated.

0

Ok, I got it working, but there is one problem:

Rule file (/etc/udev/rules/99-nas.rule) looks like this:

SUBSYSTEM=="bdi", ACTION=="add"   RUN+="/home/user/myscript.sh"
SUBSYSTEM=="bdi", ACTION=="remove"   RUN+="/home/user/myscript.sh"

(myscript.sh uses: mount -t cifs to list all mounted CIFS devices)

The problem is: when the first remote storage is mounted, then output of mount -t cifs is null. From second mount or unmount everything is normal. I don't know how to solve this problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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