Operating System - HP-UX
1834789 Members
2512 Online
110070 Solutions
New Discussion

initialize with a user different from root

 
SOLVED
Go to solution
A.K.
Frequent Advisor

initialize with a user different from root

Hello all,
I need help !!!
I created new script in /sbin/init.d to be started while the server is brought up .
I created links in sbin/rc2.d /sbin/rc3.d for kill and start the script/daemon
The problem is that I need this specific daemon to be initialize with a user different from root here is what I wrote
BTW if I remove the su - -c (change user command)
The script work just fine and initialize the daemon with the root user

if [ -x /opt/xxx/xxx/ -a -r /opt/xxx/xxx/ ]
then
APPD=su - -c "/opt/xxx/xxx// -f "
fi

what is wrong with this line ?
Thank you ,
A.K
2 REPLIES 2
Sridhar Bhaskarla
Honored Contributor
Solution

Re: initialize with a user different from root

You are trying to assign the output of your su -... command to APPD. It needs to be put in execution quotes either back ticks ` (with ~ key) or with in $(). Like

APPD=$(su - ")

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: initialize with a user different from root

The problem is that you are doing a su - my_user rather than a su my_user. I know that you want to invoke my_user's .profile BUT that is your problem. The .profile contains commands like tset, stty, and tabs that expect an interactive environment - which you ain't.

The best solution is to create a script e.g. /usr/local/bin/my_user_env.sh (that contains no exit or return statements). This script will set all the environment vars and then this script is sourced (via . /usr/local/bin/my_user_env.sh) by BOTH your init.d command AND my_user's .profile.

The less good way is to surround all the interactive commands in .profile with
if [ -t 0 ]
then
tset
stty ..
fi
If it ain't broke, I can fix that.