Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

That's because the correct syntax of the command is

/bin/su -c SOME_CMD USER

See man su.

You shouldn't assign anything to the variable $USER, BTW, because it's a system variable that holds the name of the currently logged in user.

share|improve this answer
    
First of all, thanks for the answer and the note regarding the $USER. However, it doesn't help. I still get different results. Without the /bin/su no error is shown, while when using /bin/su as you told me I get the same "Corba communication problems" error message. Any idea why does it do that? –  n00bInCpp Sep 3 '12 at 5:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.