switch user (su) not sourcing the profile


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers switch user (su) not sourcing the profile
# 1  
Old 09-05-2012
switch user (su) not sourcing the profile

Usually in solaris/Linux servers , when you do an su - username (space before and after the hyphen) the user's .profile should get sourced. But in the below linux machine it is not. As you see below ORACLE_HOME variable is not being set.

Code:
# uname -a
Linux revaltb214 2.6.18-238.el5 #1 SMP Sun Dec 19 14:22:44 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
#
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.6 (Tikanga)
#
# whoami
root
#
#
# echo #0
-bash
#
# su - oracle                   # ------> it is supposed to source oracle's .profie at this step
$
$ echo $ORACLE_HOME

$ pwd
/home/oracle

$ cat .profile
export ORACLE_HOME=/u07/oracle/11.2/client
export PATH=/usr/local/bin:/bin:/usr/bin:/home/oracle/bin:/u07/oracle/11.2/client/bin:.
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME:/lib:/usr/lib

$ . .profile                        # --------> I had to manually source the profile

$ echo $ORACLE_HOME
/u07/oracle/11.2/client

# 2  
Old 09-05-2012
Not all shells use ~/.profile. It might be looking in ~/.bashrc and the like. BASH often comes with a ~/.bashrc that reads ~/.profile but for root things might be left raw.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 09-05-2012
Ok. Got it. Thank you Corona.

How can I get both root and other OS users to use Korn Shell by default ?
# 4  
Old 09-05-2012
It is part of /etc/passwd - usually /bin/ksh. Please note, a lot of Linux boxes do not have ksh. DO NOT change root. root uses /bin/sh which is linked statically. The system may not reboot if you change it.

/bin/sh may well be bash but it will be linked so that root can boot a system without libc.so available.

Code:
usermod -s /bin/ksh  username

This User Gave Thanks to jim mcnamara For This Post:
# 5  
Old 09-05-2012
Quote:
# su - oracle # ------> it is supposed to source oracle's .profie at this step
$
$ echo $ORACLE_HOME
The su - starts a new Shell. Any environment variables set in that Shell will not be available to the parent Shell.

The way you are sourcing the script [/icode]. .profile[/icode] is the correct approach though I would use a separate script rather than the profile file. If the profile script contains commands which require a terminal (e.g. stty) then it becomes unsuitable for sourcing in background scripts.
# 6  
Old 09-05-2012
Quote:
Originally Posted by jim mcnamara
DO NOT change root. root uses /bin/sh which is linked statically.

/bin/sh may well be bash but it will be linked so that root can boot a system without libc.so available.
On RHEL, /bin/sh is a symbolic link to /bin/bash which is a dynamically (not statically) linked executable.
# 7  
Old 09-05-2012
fpmurphy -
Okay, then how can root run shell without libc? Does RHEL mount /lib somehow without a shell?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Switch from Local user to root user from a shell script?

Hi, I need to switch from local user to root user in a shell script. I need to make it automated so that it doesn't prompt for the root password. I heard the su command will do that work but it prompt for the password. and also can someone tell me whether su command spawns a new shell or... (1 Reply)
Discussion started by: Little
1 Replies

2. Shell Programming and Scripting

How to switch user using shell script ?

Hi, script1.sh script2.sh script3.sh From above, script1.sh is the main script which is executed from root user, creates installation directory, changing ownership and execution rights etc..etc.. and finally calls scripot2.sh and script3.sh to create the database as well as for post... (1 Reply)
Discussion started by: milink
1 Replies

3. Shell Programming and Scripting

sourcing .profile for other users

Hi Team, Thank you for your time. i have a situation where the user IDs of the applicatio users have been locked down to Read only. Hence I am writing a script to invoke their old .profile every time they login. My problem is : when i run . $userpath/.profile from within the ksh script... (9 Replies)
Discussion started by: anitha111
9 Replies

4. Shell Programming and Scripting

switch user from local user to root in perl

Hi Gurus, I have a script that requires me to switch from local user to root. Anyone who has an idea on this since when i switch user to root it requires me to input root password. It seems that i need to use expect module here, but i don't know how to create the object for this. ... (1 Reply)
Discussion started by: linuxgeek
1 Replies

5. Shell Programming and Scripting

switch as another user without password

I want to switch as another user without using password .Is it posiible ? I have one server B and I have logged in as username u1 but I want to login to that same server using username as u2 but I don't want to give the password for u2. (3 Replies)
Discussion started by: maitree
3 Replies

6. AIX

Switch user(su) two times

Is it possible to switch to root(if allowed) and then with root privileges switch to another user account "ABC"? To further explain the scenario, ABC is an account which has sugroups=su2DEF and root is not part of su2DEF group. but, given that root can switch to any account(correct me if I am... (7 Replies)
Discussion started by: mtwain
7 Replies

7. Shell Programming and Scripting

Switch to different user without expect

Hi, I have to switch to a different user and execute certain commands and then come back to the original user Ex: My id is 'usstage'. I need to switch to 'apstage', souce a script there, execute a function and then get back again to usstage. Please note that I do not have expect installed... (4 Replies)
Discussion started by: sugan
4 Replies

8. Solaris

rootsh on Solaris 10 is not sourcing root's .profile

I'm attempting to setup rootsh on Solaris 10 to log the activity of users who require root access. However it does not appear to be sourcing root's .profile file even when run with the '-i' option. I was wondering if anybody else has run into this and might have a solution. Thank you. (9 Replies)
Discussion started by: kungfusnwbrdr
9 Replies

9. Infrastructure Monitoring

trap in etc/profile and user .profile

Hello I really wonder what's trap in etc/profile and in each user .profile. I try to google for it but I think I have no luck. Mostly hit is SNMP traps which I think it is not the same thing. I want to know ... 1. What's a "trap 2 3" means and are there any other value I can set... (4 Replies)
Discussion started by: Smith
4 Replies
Login or Register to Ask a Question