Operating System - HP-UX
1753872 Members
7186 Online
108809 Solutions
New Discussion юеВ

Can i execute su command in pkg.cntl file cluster

 
Jimmy_13
Advisor

Can i execute su command in pkg.cntl file cluster

I need to execute: su - root -c script_name to turn on a aplication form pkg.cntl.

Is possible to do su - root in pkg.cntl?

Thanks
3 REPLIES 3
Mel Burslan
Honored Contributor

Re: Can i execute su command in pkg.cntl file cluster

your serviceguard start/stop scripts already run with root id unless there is something really funky setup on your server. Hence you do not need to su - root anywhere in your script.

if need be, you can do things like

su - oracle -c script_name

to inherit the environment variables of oracle and have the processes started have the oracle user ownership, but su - root, is something I have never heard of or seen.
________________________________
UNIX because I majored in cryptology...
Sundar_7
Honored Contributor

Re: Can i execute su command in pkg.cntl file cluster

Sure you can do su - root inside the package control script.

Under normal circumstances, as Mel has mentioned, you dont have to su - root and execute the binary since the script itself is executed with root privileges.

But if the binary/script is dependent on some variable that is set by the root's .profile , then you can use su - root.
Learn What to do ,How to do and more importantly When to do ?
A. Clay Stephenson
Acclaimed Contributor

Re: Can i execute su command in pkg.cntl file cluster

Be very careful doing su - user commands in a non-interactive environment. Most default .profiles expect to be running with a TTY input device and commands like tset, tput, tabs ... can hang or fail. There are two approaches, 1) surround any commands in the .profile with
if [ -t 0 ]
then
tset
tabs
fi

OR

create a script file which sets and exports any needed variables and let both the .profile and any scripts source the file, e.g. myenv.sh using the "." (dot) command.

. /usr/local/bin/myenv.sh

In this case you would use su user rather than su su - user. The sourced file must not contain an exit or return because it is actually part of the foreground process.

In any event, it should never be necessary to do an su root in a package.

If it ain't broke, I can fix that.