1

I have created an udeve rule (on Debian) to copy files from sdcard when it is plug in:

# only do something for sdX
KERNEL!="sd[a-z]*", GOTO="my_mount_end"
#
SUBSYSTEM=="block", ACTION=="add", ENV{PARTN}=="1",  RUN+="/usr/bin/at -M -f /usr/local/bin/SCRIPT now"    
# exit
LABEL="my_mount_end"
#

/usr/local/bin/SCRIPT is a bash script on which I want to differentiate classical use from current user and usage via the udev rule. Thus, I am trying to identify the USER that runs the script but $USER, $EUID and $(id -u) give nothing. How can I especially identify that root runs the script?

1
  • I would say id -u or id -ru should work, but I have no experience with udev. Have you considered e.g. ENV{RUN_FROM_UDEV}=="yes" and checking this in the script? I think at will pass the environment. Anyone using the script "classically" will be able to fool it by setting this environment variable anyway. Is this acceptable? May 26, 2021 at 10:56

0

You must log in to answer this question.

Browse other questions tagged .