1833870 Members
1595 Online
110063 Solutions
New Discussion

Re: strange su behaviour

 
lars eisenblatt
New Member

strange su behaviour

We are using HP-UX 11.00

When starting a mc/SG Package several su - userid -c "Commands" are started.

They do not work, because they have a different environment as in an interactive su - userid.
This is especially true for the SHELL Variable.

The (wrong?!?!) behaviour could be simulated if su is started with input redirection from /dev/null like

su - userid -c "set ; env" >out #correct env
su - userid -c "set ; env" >out
8 REPLIES 8
Mel Burslan
Honored Contributor

Re: strange su behaviour

did you try changing the default shell of this user using sam or just editing the /etc/passwd file unsing 'vipw' command ?

Looks like your "Commands" are written in a different shell language than what is set for the user by default. Most probably csh vs ksh conflict.
________________________________
UNIX because I majored in cryptology...
A. Clay Stephenson
Acclaimed Contributor

Re: strange su behaviour

This is actually rather common and is almost certainly caused by the user's .profile which the "su - user" sources as opposed to "su user" which does not. The .profile contains commands like stty, tset, tabs which expect an actual tty device to be associated with stdin. There are two ways to outbushwhack this:

1) Create a file (e.g. /usr/local/bin/userClay.sh) that sets and exports any needed environment variable but does not contain a return or exit command. Both user's .profile and your SG startup script should source this file using the shell "." (dot) operator
. /usr/local/bin/userClay.sh
This way both the profile and your startup script have the same environment.

2) Alter the .profile so that all those commands which expect stdin to be a tty device are surronded by
if [[ -t 0 ]]
then
tset ...
stty ...
tabs ...
fi
If it ain't broke, I can fix that.
Kent Ostby
Honored Contributor

Re: strange su behaviour

Lars --

Can you post the error messages from the package log here so we can see the errors.

Also, can you post the package script or at least the part that has the su - calls in it.

"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
lars eisenblatt
New Member

Re: strange su behaviour

Thanks for your answers.

In BOTH cases I USE su - userid, so it should be the same.

su - userid -c "set;env" >out gives (shortend)
ENV=/home/userid/.kshrc

OS=HP-UX
OS_VERSION=B.11.00
SHELL=/bin/ksh
SHLIB_PATH=''

su - userid -c "set ; env" >out /dev/null gives:

EDITOR=vi
ENV=/home/userid/.shrc

OS=HP-UX
OS_VERSION=B.11.00
SHELL=/sbin/sh
SHLIB_PATH=''


Funny, isn't it !

Lars
Kent Ostby
Honored Contributor

Re: strange su behaviour

Lars what shell is the shell for the user that you are running as and the user that you refer to as "userid"

"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Kent Ostby
Honored Contributor

Re: strange su behaviour

Okay .. I was able to basically reproduce it.

The /dev/null causes an error:

stty: not a typewriter

This is a known issue in ServiceGuard (and other applications doing this type of scripting) with su and the workaround is documented in :

UMCSGKBRC00012842

You can look it up in the maintanence database (I'd link it, but I only have the US link address not the European one).

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Mel Burslan
Honored Contributor

Re: strange su behaviour

I have triead the same exact commands on my single remaining 11.0 box and multiple 11.i boxes and could not reproduce the problem. The output file comes out the same for both cases.

can I suggest temporarily moving the /etc/profile and ~userid/.profile out of the way for a few seconds and run these commands without them getting in the way ? Looks like something in one of those is offending your login sequence.
________________________________
UNIX because I majored in cryptology...
A. Clay Stephenson
Acclaimed Contributor

Re: strange su behaviour

This is precisely what I was talking about; your problem is that stdin in not a tty (terminal) device and that is what is killing you with the commands in .profile that expect stdin to be a tty device.
If it ain't broke, I can fix that.