Page 1 of 1

Accessing Unix/AIX environment variables

Posted: Fri Jun 16, 2006 8:09 am
by aaikat
Can we access Unix/AIX environment variables from within a DS job (say in Job Control routine). If 'yes' then how?

Posted: Fri Jun 16, 2006 8:17 am
by kcbland
Run a shell command (DSExecute API) and use the "env" command and parse the screen output.

Posted: Mon Jun 19, 2006 1:48 am
by aaikat
In DSexecute command :

DSExecute(<NT or UV>,command,output,status)

What do I need to specify as 1st argument while running a Unix command .Is it NT or UV?

Posted: Mon Jun 19, 2006 1:54 am
by aaikat
I am just trying a run a simple batch like :

command = 'echo $PATH > /MyProjects/Path.txt'

Call DSExecute("NT",command,Output,Status)
If Status = 1 Then
Call DSLogWarn("Command Failed","JobControl")
End

Though the job gets executed sucessfully without any error or warning but not getting this file created in the directory.However can create the same file by executing the command from outside.

Posted: Mon Jun 19, 2006 2:38 am
by ArndW
Add a CALL DSLogInfo('NT Command output was "':Output:'"','') to your job to see what is happening.

Posted: Mon Jun 19, 2006 2:40 am
by ArndW
I just noticed that you are under UNIX and not Windows. Please read up on the DSExecute() command, particularly the first parameter :wink:

Posted: Mon Jun 19, 2006 4:34 am
by aaikat
Thanks for the help.

The problem was solved using 'UNIX' instead of 'NT' as shown below :-

command = 'echo $PATH > /MyProjects/Path.txt'

Call DSExecute("UNIX",command,Output,Status)
If Status = 1 Then
Call DSLogWarn("Command Failed","JobControl")
End

My next question is if I use system environment variables (like $PATH) it is running OK,if however I use user defined enviroment variables it is not working. For example,I do the following from command prompt before running job :-

export sbpath='/MyUser/recent'

then I run the batch :

command = 'echo $sbpath > /MyProjects/Path.txt'

Call DSExecute("UNIX",command,Output,Status)
If Status = 1 Then
Call DSLogWarn("Command Failed","JobControl")
End

It doesn't write the value of sbpath into Path.txt

Posted: Mon Jun 19, 2006 4:52 am
by ArndW
The datastage job is a separate process is not started with a copy of your user's environment, which is why this isn't working as you expect. You will need to explicitly set the environment variable "sbpath" in your job for this one job. If all DataStage jobs need to have this value, you can have this placed into your $DSHOME/dsenv file (and then restart DataStage to activate it)

Posted: Mon Jun 19, 2006 5:44 am
by aaikat
Hi ArndW,
I even tried that to set the variables from within the DS batch & then tried to access the variables.That also didn't work.Here was the code :

command1 = 'export sbpath=/MyProject/recent'

Call DSExecute("UNIX",command1,Output,Status)
If Status = 1 Then
Call DSLogWarn("Command Failed","JobControl")
End


command2 = 'echo $sbpath > /MyProject/Path.txt'

Call DSExecute("UNIX",command2,Output,Status)
If Status = 1 Then
Call DSLogWarn("Command Failed","JobControl")
End

Path.txt doesn't contain anything.
Is my code correct.If not plz tell me how to explicitly set the variables.

Posted: Mon Jun 19, 2006 6:00 am
by ArndW
Executing from DS opens up a new shell, so when that exits back to DataStage the variables and their values disappear as well.

Posted: Mon Jun 19, 2006 7:38 am
by kumar_s
You need to assign in the batch job and use it several place of the code and not the other way, You can this,

Path ="/MyProject/recent"

command1 = "export sbpath=":Path

command2 = 'echo " : "Path : " > /MyProject/Path.txt'

Or
command1 = 'echo /MyProject/recent'

Call DSExecute("UNIX",command1,Output,Status)

Now try using Output for /MyProject/Path.txt access.