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
? – sudodus Jul 31 '22 at 11:14Are 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? – laksdjfg Aug 01 '22 at 08:05'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
. – sudodus Aug 01 '22 at 08:40date >> /home/user/udev_test.log
worked fine, the part which failed to produce a visible result wasdate >> /tmp/udev_test.log
. This feels likePrivateTmp
but I’m not sure that actually applies toudev
rules. – Stephen Kitt Aug 01 '22 at 08:43/tmp
should have enough permissions for every possible user ID to write, so in that case only the permissions of the file are relevant. – sudodus Aug 01 '22 at 08:45udev
, 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
. – Stephen Kitt Aug 01 '22 at 08:53/tmp/udev_test.log
file already exist when you do this? I guess that it does, from the statement that you tried various modes. What happens if it doesn’t exist when you run the test (or, equivalently, if the script tries to create a new, different file, e.g.,/tmp/udev_test_$$.log
)? Modify the script to doid
,sh -c 'date >> /tmp/udev_test.log' 2>&1
andls -lai /tmp
with output to the/home
directory. Etc. – G-Man Says 'Reinstate Monica' Aug 16 '22 at 05:04