I have been testing a udev rule when plugging usb.
I guess my problem might have something to do with this post: Cannot run script using udev rules
I have the following udev rule, which successfully triggers and runs the script:
ACTION=="add", SUBSYSTEM=="block", DRIVERS=="usb", ATTRS{idProduct}=="3244", ATTRS{idVendor}=="hghh", ATTR{size}=="7685844", RUN="/home/user/trigger"
The script itself:
#!/bin/bash
date >> /home/user/udev_test.log
date >> /tmp/udev_test.log
When triggered manually the script writes to both files (with user permissions). When triggered by udev
, only file in user directory gets a date.
Also I can write to /tmp/udev_test.log
directly via something like echo "blah" >> /tmp/udev_test.log
I tried with 644, 664 and 777 on /tmp/udev_test.log
file, but nothing worked.
Why can I write there manually with user permissions, but with udev
it does not work even if permissions are set to 777?
udev
, the user is not the one you expect. Is the user in the script literallyuser
or your first name or something else or$USER
? Are there permissions when triggered byudev
to write into/home/user
?Are there permissions when triggered by udev to write into /home/user?
- do you mean what permissions the file has that was modified by udev in user directory?'udev'
allowed to write into/home/user
? Or maybe some other user ID, that initiates and tries to perform the write operation, is that user ID allowed to write there? You can check not only the permissions on the target file, but also on the directory/home/user
.udev
, only file in user directory gets a date.” seems clear enough to me. And yes,/tmp
should be writable by anything, but systemd knows how to provide a privatetmp
, which may be what’s happening here — the rule might write to a file in a privatetmp
, not the “real”/tmp
.