1837650 Members
2981 Online
110117 Solutions
New Discussion

Re: Shell scripting

 
GNOM
Frequent Advisor

Shell scripting

Hi all,

I'm programming a shell Script To start and stop an application.
my problem is that to execute some applications I have to change the user and load his Environment parameters.
using su - -c didn't succeed because there are many parmeters to load for this user.
where doing su - in the script
unix changes the user and stop running the scrip.
So I need your help because I'm learning shell scripting.
I'm working with hp-ux 11.11

Thanks for your help !!

5 REPLIES 5
Ranjith_5
Honored Contributor

Re: Shell scripting

Hi Ami,

try the following in your script.

#nohup

This allows the command to be keep ruuning even after after changing the session.

If you can post your script then people can modify that in a better way. post it if you dont mind.

Regards,
Syam
B Woolley
Occasional Advisor

Re: Shell scripting

Assuming that you can su to the specified user without a password prompt, then why not invoke another script as the command - one that ensures environment is set up correctly, and that then invokes the 'proper' command you want to run.
Florian Heigl (new acc)
Honored Contributor

Re: Shell scripting

please try using the following instead of su - ,
su user -c 'command'
I think this will solve the issue as the parameters will possibly get wiped by a full login, unless there's really really many.
yesterday I stood at the edge. Today I'm one step ahead.
Sheriff Andy
Trusted Contributor

Re: Shell scripting

Hi,
Have you tried loading the environment variables into the script of the user who you are trying to do a su - on?
I would also try as suggested above, trying to do a manual su - -c .
Rodney Hills
Honored Contributor

Re: Shell scripting

You could try the following-

#!/usr/bin/sh
echo Running this as "root"
su otheruser <echo I am now `id`
. ~otheruser/.profile
echo I now have my env variables like otheruser
...
EOF

This way even though a new shell is started for the new "su" user, it will continue to read in the script from the file. Using "." will source in the .profile.

You can now run applications (for the most part) like you were "otheruser"


HTH

-- Rod Hills
There be dragons...