Accessing Unix/AIX environment variables
Moderators: chulett, rschirm, roy
Accessing Unix/AIX environment variables
Can we access Unix/AIX environment variables from within a DS job (say in Job Control routine). If 'yes' then how?
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.
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.
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
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
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)
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.
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.
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.
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'