In the rules file a script is executed by passing the arguments "LABEL" and "DEVNAME" for mounting
ACTION=="add", RUN+="/appmount/scripts/usb_mount.sh %E{ID_FS_LABEL} %E{DEVNAME}"
In the usb_mount.sh file printing the arguments value as
echo "LABEL: $1 DEVNAME: $2" # this does not work reliably
Some of the devices have empty LABEL field and hence the DEVNAME is printed as the label. In the bash script we can pass the args in double quotes and it will work even if the args are null.
What is the equivalent of the same for passing args to udev rules?
The workaround to this problem might be to switch the order of the arguments. Is there any reliable way?
RULES FILES. The udev rules are read from the files located in the system rules directory /lib/udev/rules. d, the volatile runtime directory /run/udev/rules. d and the local administration directory /etc/udev/rules.
A udev rule must contain one attribute from one single parent device. Parent attributes are things that describe a device from the most basic level, such as it's something that has been plugged into a physical port or it is something with a size or this is a removable device.
As the successor of devfsd and hotplug, udev primarily manages device nodes in the /dev directory. At the same time, udev also handles all user space events raised when hardware devices are added into the system or removed from it, including firmware loading as required by certain devices.
You should be able to use single quotes instead of the double quotes you mentioned:
ACTION=="add", RUN+="/appmount/scripts/usb_mount.sh '%E{ID_FS_LABEL}' '%E{DEVNAME}'"
Beware: I didn't test this. Maybe variable substitution will fail within single quotes...
Quoting from man udev
about the key "RUN":
The program name and following arguments are separated by spaces. Single quotes can be used to specify arguments with spaces.
Just set and query udev's env, here an example to check if system is running VMWare :
cat /etc/udev/rules.d/99-vmware.rules
KERNEL=="id", SUBSYSTEM=="dmi", ATTR{sys_vendor}=="VMware, Inc.", ENV{VMWARE}='defined'
udevadm info -e | grep 'VMWARE='
E: VMWARE=defined
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With