HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Chapter III - User's environments and /etc/profile

 
SOLVED
Go to solution
rustam_2
Super Advisor

Chapter III - User's environments and /etc/profile

Hi everybody,
I'd like to find out some details about environments, how to create them correctly and how to edit profile file.
1. to set temporary (for current session) environment. I needed to environment for ORACLE_HOME and ORACLE_SID.
i did:
# cd /u01/app/oracle/product/10.2.0/db_1/bin
# PATH=$PATH:.
# export PATH
# .oraenv
after this i could run oracle commands. When i changed user and came back, i couldnt do

$echo $PATH
PATH: .

in my 2nd server:
$echo $PATH returns
/usr/bin:/usr/sbin:/sbin

so, how could i have normal PATH value? in both of them i must have PATH for OS commands and ORACLE env.
Should i run PATH=PATH:/usr/bin:/usr/sbin:/sbin:/u01/app/oracle/product/10.2.0/db_1/bin or ? I know how to set one PATH(env), such as:
# cd /u01/app/oracle/product/10.2.0/db_1/bin
# PATH=$PATH:.
# export PATH
but i need to set whole environments with 1-2 command, i'd like to find out syntax of 'set environments'

2. First mark was to set temporary environments and syntax. Better to check and know what is running right now. But for the future i'd like to know - how to edit /etc/profile and ~/.profile, coz dont wanna always
set environments after relogin\restart\shutdown and so on. I checked /etc/profile and a bit difficult to find where to put environments..? + i couldnt find .profile in my home directory.

Regards,
Rustam



40 REPLIES
Yallappa
Occasional Advisor

Re: Chapter III - User's environments and /etc/profile

Edit .profile file of user with vi editor and change the line
PATH=$PATH:.

to

PATH=$PATH:/u01/app/oracle/product/10.2.0/db_1/bin

and then try.
Michal Kapalka (mikap)
Honored Contributor

Re: Chapter III - User's environments and /etc/profile

hi,

i think if you like to run some commands you need to set the variables for the shell, i always use only a dedicated user for oracle administration, so only this user need to set up this shell variables. of course if you have only one instance on the oracle you could set this variables as a global variable in /etc/profile.

mikap
Horia Chirculescu
Honored Contributor

Re: Chapter III - User's environments and /etc/profile

Hello, Rustam

>so, how could i have normal PATH value?

You could do a:

source /etc/profile

That would restore the PATH to a "normal" value...

>i'd like to know - how to edit /etc/profile

You do not need to edit /etc/profile in order to alter PATH value. Change the file /etc/PATH .

Horia.
Best regards from Romania,
Horia.

Re: Chapter III - User's environments and /etc/profile

>Horia: You could do a: source /etc/profile

To source a file in a real shell you use:
. /etc/profile
rustam_2
Super Advisor

Re: Chapter III - User's environments and /etc/profile

few days ago i couldn't run oracle command, coz environments weren't set. Then i run on 1st server these commands:
# cd /u01/app/oracle/product/10.2.0/db_1/bin
# PATH=$PATH:.
# export PATH
# .oraenv
then it were possible to run them. But know i cant run OS commands, coz in PATH=PATH: .

on 2nd server i didn't run any command yet, there PATH=/usr/bin:/usr/sbin:/sbin

So how can i have set
PATH=/usr/bin:/usr/sbin:/sbin:/u01/app/oracle/product/10.2.0/db_1/bin
through the CLI?

+ 2nd way, should i add these parameters in /etc/profile or /etc/path ?

i have special user for oracle DBA.


Re: Chapter III - User's environments and /etc/profile

>So how can I have set:
PATH=/usr/bin:/usr/sbin:/sbin:/u01/app/oracle/product/10.2.0/db_1/bin

You type that exact line.
rustam_2
Super Advisor

Re: Chapter III - User's environments and /etc/profile

Dennis, do u mean like this?:

$PATH=PATH:/usr/bin:/usr/sbin:/sbin:/u01/app/oracle/product/10.2.0/db_1/bin

$export PATH
Horia Chirculescu
Honored Contributor

Re: Chapter III - User's environments and /etc/profile

>$PATH=PATH:...

It is the other way:

PATH=$PATH:...


Horia.
Best regards from Romania,
Horia.

Re: Chapter III - User's environments and /etc/profile

>should I add these parameters in /etc/profile or /etc/path?

It depends on how many user's want this in their path vs how many don't.
Special users should add it to their own ~/.profile.
rustam_2
Super Advisor

Re: Chapter III - User's environments and /etc/profile

Thanks a lot for all of you. You(all) and me solved first problem, i.e. could set mix environments via CLI.

----
>>>> It depends on how many user's want this in their path vs how many don't.

Honestly, i dont know. I just have 2 users, root and oracle. These are just DB server and will not be other services. So should i set these environments for global or just oracle? Could u give me an idea\advice?

P.S. Yesterday, i e-mail to person who used before this server and he answered that there probably might be environments in the bash_profile,or in the bashrc, or in the .profile. How can i check bash_profile and bashrc? (whereis and find didnt help).

Regards,
Rustam
Horia Chirculescu
Honored Contributor

Re: Chapter III - User's environments and /etc/profile

> How can i check bash_profile and bashrc? (whereis and find didnt help).

bash_profile can be found on $HOME directory from every user having bash as the shell. I doubt that you are using bash on HP-UX.

bashrc also is related to bash shell.

Those are Linux common shells.

On HP-UX you are using by default bourne shell

This shell is using profile (actually it is .profile) on the same $HOME directory for each user.

man sh-bourne

Horia.
Best regards from Romania,
Horia.
Horia Chirculescu
Honored Contributor

Re: Chapter III - User's environments and /etc/profile

"Those are Linux common shells" - > "This is a linux common shell"

I was talking about bash.

Horia.
Best regards from Romania,
Horia.
James R. Ferguson
Acclaimed Contributor

Re: Chapter III - User's environments and /etc/profile

Hi:

> Horia: On HP-UX you are using by default bourne shell

No, you are using the Posix shell. The old Bourne shell is long gone. HP-UX uses the Posix shell (see the manpages for 'sh-posix').

Normal users use '/usr/bin/sh' which is compiled with dynamic libraries and minimizes the running memory footprint. The root account has the '/sbin/sh' as the default shell since this is compiled with static libraries that do not require the '/usr' filesystem to be mounted during startup.

Never change 'root's default shell (in '/etc/passwd') from '/sbin/sh' to anything else. To do so may leave you with an un-bootable system.

Regards!

...JRF...

Re: Chapter III - User's environments and /etc/profile

>I just have 2 users, root and oracle.

Then you just modify ~/.profile of the user that needs those extra PATH directories.

As Horia said, ~ is a shortcut for $HOME.
Horia Chirculescu
Honored Contributor

Re: Chapter III - User's environments and /etc/profile

>No, you are using the Posix shell. The old Bourne shell is long gone. HP-UX uses the Posix shell (see the manpages for 'sh-posix').

Thank you for the necessary correction, James.

Like bourne shell, posix is using .profile and /etc/profile.

Anyway, this would lead to the following obvious observation: Should find out what shell is using the oracle user. If it is a bourne, korn or standard posix shell, you should look for profile files (should be $HOME/.profile). If it a csh, then you should look for .cshrc

If the shell is bash then you should look for .bash_profile. But if you did not find /etc/bashrc file, then probably bash is not installed on your system.

Horia.
Best regards from Romania,
Horia.
rustam_2
Super Advisor

Re: Chapter III - User's environments and /etc/profile

Thank you, Horia,JRF,Dennis
I read some e-books about setting of user's environment and found out some details.
now i know different between /etc/profile and ~/.profile and when each one runs.

I found out interesting things. All environments which are i set through the CLI and found in ~./bash_profile, not in ~./profile. So ex-DBA set them in ~./bash_profile before. As far as i know ~./bash_profile runs when my shell is bash, right? i checked and found that my current SHELL is SH
SHELL="/sbin/sh"
SHLVL="3"
TERM="vt100"
TZ="WST-5WSTDST"

So should i change my SHELL then do i have to change these environments in another profile file? I mean does SH SHELL is ok? or which shell is suitable for use?
And what does CDE login mean?
Horia Chirculescu
Honored Contributor

Re: Chapter III - User's environments and /etc/profile

>All environments which are i set through the CLI and found in ~./bash_profile, not in ~./profile.

One observation: the variables that you set on your current shell

meaning by invoking:

VAR=value
export VAR

would exist only in that shell session. The profile file for the current user would not be affected by only setting a variable in the CLI.


>So ex-DBA set them in ~./bash_profile before.

This means that your ex-DBA used bash as a login shell.


>As far as i know ~./bash_profile runs when my shell is bash, right? i checked and found that my current SHELL is SH
SHELL="/sbin/sh"
SHLVL="3"
TERM="vt100"
TZ="WST-5WSTDST"


So you use the standard posix shell. This means that you must edit .profile for that user.


>So should i change my SHELL then do i have to change these environments in another profile file?


Yes, depending on the shell you use you need to update a different file. As usual, read manual page for the shell you use.


>I mean does SH SHELL is ok? or which shell is suitable for use?

Posix shell would be just fine. Just set the correct environment for your application.

Horia.
Best regards from Romania,
Horia.

Re: Chapter III - User's environments and /etc/profile

>about setting of user's environment

(This is typically called setting environment variables.)

>~./bash_profile runs when my shell is bash, right?

Yes.

>I checked and found that my current SHELL is SH: SHELL="/sbin/sh"

No, that just says your login shell is sh.

>So should I change my SHELL then do I have to change these environments in another profile file?

Only if you want $SHELL to be accurate.

>does SH SHELL is ok? or which shell is suitable for use?

Sure, the Posix shell is the default HP-UX shell.

>And what does CDE login mean?

That's what you have when you have a workstation and you use the graphical interface to login.
rustam_2
Super Advisor

Re: Chapter III - User's environments and /etc/profile

So during setting environment variables i face dilemma.
Should i change ~/.profile for using SHELL sh or should i change shell to bash for using ~/.bash_profile?

1. if first way- sh, what should set\type in ~/.profile? i checked and found some operators

2. if the second - bash, what should i do to change shell from sh to bash?

regards and thank you,
rustam
Horia Chirculescu
Honored Contributor
Solution

Re: Chapter III - User's environments and /etc/profile

>if first way- sh, what should set\type in ~/.profile? i checked and found some operators

You have to set up the shell variables, as in

export ORACLE_HOME=...
export ORACLE_BASE=...
export ORACLE_SID=...
and so on.

>2. if the second - bash, what should i do to change shell from sh to bash?

You have to edit the file /etc/passwd

and modify the shell from the posix shell (usr/bin/sh) to bash

And edit the corresponding profile file.

Horia.
Best regards from Romania,
Horia.

Re: Chapter III - User's environments and /etc/profile

>1. if first way - sh, what should set\type in ~/.profile? I checked and found some operators

(BTW, the correct punctuation is "/", not "\". "\" is used in windows paths and on Unix for escaping.)

If you use a real shell (sh/ksh), ~/.profile should already be set up. You then can customize it the way you want, as Horia suggested.
rustam_2
Super Advisor

Re: Chapter III - User's environments and /etc/profile

Horia and Dennis,
1. i checked passwd. The interpreter is /bin/bash
so why it didnt run the file .bash_pforile? or in passwd must be /usr/bin/bash?

2. my .bash_profile has these values:

# more .bash_profile
MANPATH=/usr/local/share/man:$MANPATH
EDITOR=vi
LESS="-efFKMX"
PS1='\u@\h \W\$ '
# DISPLAY=my_ip:666.0
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
ORACLE_SID=prod
ORACLE_HOSTNAME=oraprod
NLS_LANG=_.AL32UTF8
TMP=/tmp/$LOGNAME
TMPDIR=/tmp/$LOGNAME
#
PATH=/usr/local/bin:$PATH:$ORACLE_HOME/bin

export PATH MANPATH EDITOR LESS ORACLE_HOME ORACLE_SID ORACLE_HOSTNAME TMP TMPDI R NLS_LANG

test -f ~/.aliases && . ~/.aliases
dat=`date +%Y-%m-%d_%H%M`
umask 022

so if i want to sh/ksh i have to copy these values and paste in .profile or ..?

regards,
rustam
Horia Chirculescu
Honored Contributor

Re: Chapter III - User's environments and /etc/profile

Hello,

>1. i checked passwd. The interpreter is /bin/bash
>so why it didnt run the file .bash_pforile?

The only situation when bash does not interpret the profile file, is when the binary itself is called with --noprofile option.

>or in passwd must be /usr/bin/bash?

You must know where your shell binary exists (if it is /bin/bash or /usr/bin/bash). But if you are able to log into the machine as this user, I believe /bin/bash is your binary used as the shell. (You can use `find` or `which` in order to find out the exact location)



>so if i want to sh/ksh i have to copy these values and paste in .profile or ..?

Yes, you must add the following variables into your .profile:

ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
ORACLE_SID=prod
ORACLE_HOSTNAME=oraprod
NLS_LANG=_.AL32UTF8

export ORACLE_HOME ORACLE_SID ORACLE_HOSTNAME NLS_LANG

Horia.
Best regards from Romania,
Horia.

Re: Chapter III - User's environments and /etc/profile

>1. I checked passwd. The interpreter is /bin/bash
>so why it didn't run the file .bash_profile? or in passwd must be /usr/bin/bash?

Does ~/.bash_profile exist?

Typically there is a tlink that sets /bin to /usr/bin, so both bash paths should be fine.

>export PATH MANPATH EDITOR LESS ...

If you don't have to worry about the Bourne shell, you may want to use:
export MANPATH=/usr/local/share/man:$MANPATH

>if I want to sh/ksh I have to copy these values and paste in .profile or ..?

You can just use ~/.profile and not ~/.bash_profile. Or only put your bash specific stuff in ~/.bash_profile.