System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Command run under 'su' doesn't work right

 
SOLVED
Go to solution
Jayson Hurd_2
Advisor

Command run under 'su' doesn't work right

I have a command that I run in UNIX as a user called "cognos":

$ /jv77/cognos/cer3/bin/configcp -t /jv77/cognos/cer3/bin/start.ccp

It runs as it should.

When I run it this way logged in as root:

su -cognos -c "/jv77/cognos/cer3/bin/configcp -t /jv77/cognos/cer3/bin/start.ccp"

It gives me errors that certain files can't be found. Does this -c actually invoke the cognos user's profile? It seems paths aren't being established, or that it's using root's path, etc....
Most things worth having don't come easily.
7 REPLIES 7
Jeff Schussele
Honored Contributor
Solution

Re: Command run under 'su' doesn't work right

HI Jayson,

No, the dash between su & username sources the user's environment.
But there MUST be spaces on both sides.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Geoff Wild
Honored Contributor

Re: Command run under 'su' doesn't work right

Sounds like the env isn't loading....

Try this:

su -cognos
env

then

su -cognos -c env

Different?


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: Command run under 'su' doesn't work right

Try doing it like this:

su - cognos -i -c "/jv77/cognos/cer3/bin/configcp -t /jv77/cognos/cer3/bin/start.ccp"

That will run the shell in interactive mode.


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Dwyane Everts_1
Honored Contributor

Re: Command run under 'su' doesn't work right

Jayson,

Try this:

su - cognos -c '/jv77/cognos/cer3/bin/configcp -t /jv77/cognos/cer3/bin/start.ccp'

Note the spacing and 'quote' change.

D
Dave La Mar
Honored Contributor

Re: Command run under 'su' doesn't work right

Jayson -
This is a very common problem. As others mentioned, most often it involves env variables.
In out shop we are accustomed to place exports of the required environment variables in the script to be executed.
Having done this, we seldom encounter any errors.
Yes, this means acouple of export XXX="YYY" in your script to execute, but it sure relieves some headaches.

Regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
Jayson Hurd_2
Advisor

Re: Command run under 'su' doesn't work right

If I put it on separate lines, it just comes back to the prompt and then stops. The script halts, essentially...
Most things worth having don't come easily.
Michael Schulte zur Sur
Honored Contributor

Re: Command run under 'su' doesn't work right

Hi,

what wonders me is, it should have complained about an invalid option since there is no space after the -. Probably he does interpret this as additional command and tries to run it as root. If you put a command on two lines, you will have to use a continuation character, so the two lines will be interpreted as one and I think it is the \, you will have to use at the end of line one. But still the su - cognos should work. It will read the .profile and execute the command.

greetings,

Michael