Set global environment variables at boot in Solaris 11

environment-variablessolarisstartup

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?

Best Answer

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/
Related Question