Accessing Unix/AIX environment variables

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
aaikat
Participant
Posts: 47
Joined: Tue Mar 07, 2006 2:49 am

Accessing Unix/AIX environment variables

Post by aaikat »

Can we access Unix/AIX environment variables from within a DS job (say in Job Control routine). If 'yes' then how?
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Run a shell command (DSExecute API) and use the "env" command and parse the screen output.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
aaikat
Participant
Posts: 47
Joined: Tue Mar 07, 2006 2:49 am

Post 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?
aaikat
Participant
Posts: 47
Joined: Tue Mar 07, 2006 2:49 am

Post 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.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Add a CALL DSLogInfo('NT Command output was "':Output:'"','') to your job to see what is happening.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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:
aaikat
Participant
Posts: 47
Joined: Tue Mar 07, 2006 2:49 am

Post 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
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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)
aaikat
Participant
Posts: 47
Joined: Tue Mar 07, 2006 2:49 am

Post 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.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post 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.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
Post Reply