I am trying to write a udev rule for USB drive plugin. I want to first mount it to /media and then run the script at /usr/local/bin/script.sh. When I insert the USB, it doesn't even mount the device with this rule. However, If I manually type the part in RUN into terminal, It mounts and executes script.

The rule file says:

ACTION=="add", KERNEL=="sd[a-z]*", RUN+="/bin/mount -t auto /dev/%k /media/ && /usr/local/bin/script.sh"

Is this the right way to execute two commands in RUN section of the rule?

有帮助吗?

解决方案

/bin/mount doesn't take && as an argument. If you want a shell chain to be executed then you must pass it to a shell.

RUN+="/bin/sh -c '...'"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top