I tried to search the forums for this topic, but unfortunately "su" isn't a valid search term.
I have a set of scripts that need to run as root, and at times they
Thanks!
Kevin Barry
I have a set of scripts that need to run as root, and at times they
su
to a normal user to execute other commands, e.g., su -m ta0kira -c 'find .'
or the like. This is fine in most cases, but I realized that su
unconditionally steals terminal control if I run my script from a terminal (su.c:453). The effect can be replicated by doing the following as @root: su -m nobody -c 'find /var' | less
. less
will stop in the background, but su
will be in the foreground wait
ing for the child process to exit. So, I guess I have three options here:- Always follow
su
with2> /dev/null
in scripts so it doesn't take terminal control. - Modify
su
so that it doesn't take terminal control when arguments are passed. Note that if PAM needs a password, the respective module should steal terminal control as needed. - Use something other than
su
to change users.
sudo
) is not an acceptable solution. On Linux, su
doesn't steal terminal control and things work just fine, so I'm tempted to take my second option above.Thanks!
Kevin Barry
Last edited by a moderator: