Operating System - HP-UX
1825766 Members
2065 Online
109687 Solutions
New Discussion

Re: su from root to user account does not execute .profile and set up env

 
Gus Mestousis
Frequent Advisor

su from root to user account does not execute .profile and set up env

On HPUX 11.23 is there a setting that would prevent root from executing a user’s .profile?

I am running the following command:
su appuser -c "/home/appusers/script.sh /home/appuser"

Where appuser is the username and the script is script.sh located in the home directory and needs to have the argument of the location afterwards. If I login as the user the .profile sets up all the environmental variables and the script runs fine, but if I run it as root through that command it does not run because its environment is not set up correctly.

I don't think any special options need to get passed to su to run the .profile and set up the environment. I'm only having and issue on one single server. It runs fine on the others. I thought there might be some security setting somewhere preventing it but I checked /etc/default/security and they match up fine. Any ideas? Thanks!
Sure, let me just drop everything and work on your problem.
8 REPLIES 8
Alan Meyer_4
Respected Contributor

Re: su from root to user account does not execute .profile and set up env

To execute the users environment, you need a dash between the su and the username

su - username

" I may not be certified, but I am certifiable... "
Rick Garland
Honored Contributor

Re: su from root to user account does not execute .profile and set up env

Need that hyphen after the 'su'

su - newuser

With the hyphen you get the newuser env.
Without the hyphen you do not get the env

Raj D.
Honored Contributor

Re: su from root to user account does not execute .profile and set up env

Hi Gus ,

You can try the following ..

su appuser -c "/home/appusers/script.sh /home/appuser"


Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: su from root to user account does not execute .profile and set up env

oops ..I too missed the hyphen..

# su - appuser -c "/home/appusers/script.sh /home/appuser"

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
yut
Advisor

Re: su from root to user account does not execute .profile and set up env

for execute .profile, run command su - username


-yut-
morganelan
Trusted Contributor

Re: su from root to user account does not execute .profile and set up env

Become user test while retaining the previously exported environment:#su test

Become user test but change the environment to what would be expected if bin had originally logged in:#su - test
Kamal Mirdad
Orhan Biyiklioglu
Respected Contributor

Re: su from root to user account does not execute .profile and set up env

man 1 su

- If the - option is specified, the new shell starts up as if the new user had initiated a new login session. If the - option is omitted, the new shell starts as if a subshell was invoked.

Since login shells execute .profile you need to use - to make the new shell a login shell.
Muthukumar_5
Honored Contributor

Re: su from root to user account does not execute .profile and set up env

When you are executing su appuser -c "command" from root user then, it will retain root user's exported environment settings only.

You can feel this as,

# su appuser -c "echo hi"
# hi

When we are executing su - appuser -c "command" from root user then, it will use new user's environment settings.

# su - appuser -c "echo hi"

# hi

hth.
Easy to suggest when don't know about the problem!