running a command as root with /bin/su and without gives different results
Posted
by
n00bInCpp
on Server Fault
See other posts from Server Fault
or by n00bInCpp
Published on 2012-09-02T17:12:00Z
Indexed on
2012/09/03
9:40 UTC
Read the original article
Hit count: 261
Some background: I have a machine with SLES 11 installed. I am running a bash script that one of its lines is /bin/su $USER -c SOME_CMD
.
Unfortunately, the SOME_CMD
that comes after the -c
keeps failing, no matter if USER=root
or any different user. However, if /bin/su $USER -c
part is omitted then everything runs smoothly. Moreover, I have run the script on RHEL5 and it worked fine.
Anyway, my question is why does it happen? If it is a permissions problems then why when I run this as root with /bin/su
and without I get different results?
P.S. apologize if somebody else has asked it before, I have done many googling and got nothing that satisfies.
Thanks in advance, n00bInCpp
EDIT
Okay, I figured it out, I hope so.
Instead of running /bin/su
I used /user/bin/sudo -u $MY_USER_1 MY_ENV_VAR="/home/user1" SOME_CMD
. I don't understand why I have to use sudo
, though. I am used to run a command as a different user using su
and not worrying about permissions problems, but I guess it doesn't work like that on SLES 11
/SuSE
.
Anyhow, thanks to everyone who wanted to or helped me.
© Server Fault or respective owner