Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am wanting to create a file in Solaris, so that I can export a few "items" whenever the machine is started up.

i.e.

I want to export ORACLE_HOME and ORACLE_SID and some other directories, of my own, when the machine has started up.

These are the 2 Oracle folders I need to export:

export ORACLE_HOME=/oracle/product/11.1.0/db_1/
export ORACLE_SID=orcl

This is the other folder I need to export of my own:

export TESTFOLDER_DIR=/test/testfolder/bin/

It is highly irritating that I have to do it every time the machine has started up.

I have tried Googling it, but I have not seen anything yet (still searching). It is easy to make the file with the export commands, but to put it somewhere that the machine will know to use them in startup, is the issue.

Is there a way I could do it?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

If these variables need to be set for every account, the simpler would be to add the export statements to /etc/profile. This file is not root's profile but a file sourced for every account using an interactive Bourne shell family shell (sh, ksh, bash, ...)

You can then just add at the end of this file.

export ORACLE_HOME=/oracle/product/11.1.0/db_1/
export ORACLE_SID=orcl
export TESTFOLDER_DIR=/test/testfolder/bin/

Otherwise, just add these three lines in your shell startup file (likely one of $HOME/.profile or $HOME/.bash_profile).

If you are logging in as root (which is not a good practice), that would be /.profile or /root/.profile

Finally, should you want to unconditionally set these variables whatever the shell is used and even for non interactive login stuff, like services, you can use the /etc/default/init file. Note that the export builtin is not required in this file as it is not a real shell script but really a configuration file, eg:

ORACLE_HOME=/oracle/product/11.1.0/db_1/
ORACLE_SID=orcl
TESTFOLDER_DIR=/test/testfolder/bin/
share|improve this answer
    
Thanks for that. I have found export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC in the /etc/profile file. DO I put them in there? This is the root's profile. –  Kevdog777 Feb 26 '13 at 9:54
    
Root profile is either /.profile or /root/.profile. Answer updated to clarify. –  jlliagre Feb 26 '13 at 10:05
    
/etc/profile only applies to interactive logins, not to system services. For completeness, how can you define environment variables that also apply to services started by init under Solaris? –  Gilles Feb 26 '13 at 22:45
    
@Gilles Answer updated with the supported method to define these kind of variables. –  jlliagre Feb 26 '13 at 23:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.