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.
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.