I am looking for some support with an issue I have come across today. What I am trying to do:
I am trying to use udev rules to trigger a python script which does multiple things including making a directory /mnt/usbKey and mounting a usbstick located at /dev/sdc1, this is triggered when it finds a device added to /dev/sdc.
Where I have got so far:
I can trigger a .py script when I plug in the usb stick no problem, I can have a script make the directory /mnt/usbKey but it does not mount the drive. While troubleshooting this I have found that if I call the script using sudo ./commandTest.py it both makes the directory and mounts the usb stick as planned. When the udev rule calls it however it will not work.
For the purpose of testing, The content of commandTest.py is:
#!/usr/bin/env python3 import subprocess import os os.system('mkdir /mnt/usbKey') os.system('mount /dev/sdc1 /mnt/usbKey')
The udev rule is /etc/udev/rules.d/80-local.rules and the contents are:
SUBSYSTEM=="block", ACTION=="add",KERNEL=="sdc*",``RUN+=" /usr/bin/python /home/user/commandTest.py"
I have been doing some reading and cannot understand why if udev runs as root it will not mount this device, even though the same script called locally works fine. is there some environment variables which need set? any advice welcome.