Unix Environment Script

Hi,

I was wondering what is the best way to write a centralized unix environment script. This script would set the application environment variables per specific environment. e.g. dev, qa, test or prod.

We currenlty have 2 types of env files e.g. .envfile and set.env per environment. These contain all the necessary application variables that need to be set. And these are set through the calling script via . .envfile or . set.env (we dot the file to set/export the variables.) We would like to consolidate these env files.

How could we accomplish to have only one env shell script to set 4 different environemnts? I guess this need to be based on "host" and/or "user" per environment.

I would appreciate your thoughts on this topic.

Thanks in advance,

AC

Since you want it for all users put the code in /etc/profile.

You would be better off keeping those variable declarations if four separate files:
prod_env.shl
qa_env.shl
test_env.shl
dev_env.shl

Then execute the correct script based on hostname:

hname=`hostname`
if [ $hostname = "dev" ] ; then
  .  /path/to/dev_env.shl
fi
........ and so on

Thanks for the information.

Do we name the 4 env files suffixed with .sh. We currently have 2 diff types of env files as .envdev and set.dev. I also want to make sure these files just have variables exported and what is the industry standard for naming these environment files.

AC

oops a slight typo there by Jim

hname=`hostname`
if [ $hname = "dev" ] ; then ### not $hostname
. /path/to/dev_env.shl
fi
........ and so on

=============================================

but want to know, is the hostname the criteria to decide what env script you are going to run ? If yes, then you can simply put the respective scripts in the /etc/profile directly, instead of having a wrapper script, coz anyway when you know what you want to run on "dev" you even dont want to check if it is "dev" on "dev", so simply put that "dev.sh" in /etc/profile of "dev" and same for others.
-

We do not have a separate server for each environment. Infact we have all the environments except pord on the same server. Does it make sense to set the env variable in the .profile per user account per environment or set using the centralized env script.