Pass UNIX environment variable to DataStage jobs

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Hongqing Tang
Premium Member
Premium Member
Posts: 12
Joined: Thu Apr 27, 2006 3:17 pm
Location: Bay Area

Pass UNIX environment variable to DataStage jobs

Post by Hongqing Tang »

I want to pass UNIX environment variables to datastage job. IN the job property, I entered the UNIX envrionment variable's name $SCHEMA_NAME, this is a unix environment variable with a value USA. In the parameter's default value, I entered $ENV. When I run the job, I expect that the parameter will get USA as it's default value, instead, it shows $ENV. It did not resolve the $ENV to get the value from UNIX environment. Did I do something wrong? How do I set it up so that it will get the value from UNIX environment when it is $ENV?
pravin1581
Premium Member
Premium Member
Posts: 497
Joined: Sun Dec 17, 2006 11:52 pm
Location: Kolkata
Contact:

Re: Pass UNIX environment variable to DataStage jobs

Post by pravin1581 »

In the parameter's default value put $PROJDEF.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

More to it than that. You first need to define it in the Project as a user-defined environment variable using the Administrator and that sounds like the step you missed. There you would set its value to $ENV which means it will take the current value from the job's environment.

Then in the job, add the variable from the picklist and change what it defaults to to $PROJDEF as suggested - that will get you the Project Default which in your case is $ENV.

In some cases, like say in a Transformer, you can simply fetch it from the environment using (off the top of my head) the GetEnvironment() function. Note that when you pass it the name of the variable, do not include the dollar sign. Best to do this in the Initial Value of a Stage Variable and then reference it there, making sure the derivation is left empty, that gets the value one time when the job starts and then leaves it static over the course of the job. FYI.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Hongqing Tang
Premium Member
Premium Member
Posts: 12
Joined: Thu Apr 27, 2006 3:17 pm
Location: Bay Area

Post by Hongqing Tang »

I followed what you said here, added SCHEMA_NAME environment variable in Administrator and set its value as $ENV. Then in the DS job, I added the variable by picking it up from the "Add Environment Variable...". Then I changed its default $ENV to $PROJDEF. Compile and run the job. I wrote the value of this parameter out and it is $ENV, it did not get the UNIX environmental value USA. Why it could not see the UNIX environmental value? Did I miss something? Do we need to do some setup in the DS project level?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Is the environment variable's value set in the shell of the process that runs the job (dsapi_server or dsapi_slave, perhaps)?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Hongqing Tang
Premium Member
Premium Member
Posts: 12
Joined: Thu Apr 27, 2006 3:17 pm
Location: Bay Area

Post by Hongqing Tang »

I am not sure. How do you check that? How do you set it up in the shell if they are not there? Thanks so much in advance.
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Use set command to display all the environment variables set in your shell
You are the creator of your destiny - Swami Vivekananda
Hongqing Tang
Premium Member
Premium Member
Posts: 12
Joined: Thu Apr 27, 2006 3:17 pm
Location: Bay Area

Post by Hongqing Tang »

I used set in my home and root directory and it displayed all of the environment variables. I do not see the environment variable SCHEMA_NAME which I thought was there with value USA.
Hongqing Tang
Premium Member
Premium Member
Posts: 12
Joined: Thu Apr 27, 2006 3:17 pm
Location: Bay Area

Post by Hongqing Tang »

I added the environment variable SCHEMA_NAME in my home dir's .profile file. But value USA is still not passed to the DS job. Am I missing anything else?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Then it's not in the right environment, the one the job uses when it runs. Set it in dsenv instead. That or explicitly set the vaule in the Project to what you need it to be (this rather than $ENV) but still stick with $PROJDEF in the job.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Hongqing Tang wrote:I am not sure. How do you check that? How do you set it up in the shell if they are not there? Thanks so much in advance.
Use a before-job subroutine in any job - even a test job - to invoke a command like echo $SCHEMA_NAME via the ExecSH subroutine.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Second log message of any job will have a complete dump of all environment variables in effect when the job ran.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Hongqing Tang
Premium Member
Premium Member
Posts: 12
Joined: Thu Apr 27, 2006 3:17 pm
Location: Bay Area

Post by Hongqing Tang »

Second log message of any job will have a complete dump of all environment variables in effect when the job ran.

I checked the log earlier, and SCHEMA_NAME is not one of the environment variables listed there.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

That suggests that SCHEMA_NAME is not defined in the executing user's environment. Try setting SCHEMA_NAME in the dsenv script, as earlier advised. Or in the .profile file of the executing user, if you must.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply