cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

3007
Views
0
Helpful
5
Replies
MartinLeBrun
Beginner

How to set a variable's value from job output

Can anyone point me at documentation on how to set the value of a variable based on the output of a job? We are running TES v6.0.2.153.

The Agent/Adapter is a Linux command line, so the Command could be for example:

echo foo

and I would like a variable named bar to contain the value foo.  (Obviously in real life the variable value would be dependent on what the command output)

Thanks in advance,

Martin

1 ACCEPTED SOLUTION

Accepted Solutions
rami_rgare
Beginner

Martin,

I would use Job Event and Variable Action;

- Create your global variable as string type or whatever applicable to the anticipated value.

- Create a Variable Action and point it to the variable you've created and then chose "set variable value to" and under the value type

- Create a job event and associate it to your job and then assign the above variable action to it.

- Run the job and then check of the Var's value is the actual output of your job.

This is the easiest/quickest way to achieve your requirement.

enjoy...

View solution in original post

5 REPLIES 5
rami_rgare
Beginner

Martin,

I would use Job Event and Variable Action;

- Create your global variable as string type or whatever applicable to the anticipated value.

- Create a Variable Action and point it to the variable you've created and then chose "set variable value to" and under the value type

- Create a job event and associate it to your job and then assign the above variable action to it.

- Run the job and then check of the Var's value is the actual output of your job.

This is the easiest/quickest way to achieve your requirement.

enjoy...

View solution in original post

Thank you Rami for your quick and accurate reply.  That worked.

My next issue is that I have a Linux .bash_profile script that is automatically running before the command in the job and the output of that is prefixed to the job output in the variable.  (This is probably outside the scope of Tidal - I will have to see if I can modify the .bash_profile script to be silent when called from Tidal.)

Thanks again,

Martin.

Glad to hear it worked

Actually i think you can work somehting out for the bash profile from Tidal , on your job click on options and from there check the option for Linux use bash profile... i recall I used that in the past to let Tidal authenticate itself using the service's account's bash profile when running.. hope that will work it out for you without reoding your script..

Not sure if you are using the same account that the agent is running under on your server but try that option and see if it will make any different.

if it doesnt work, i recall another scenario where we used environment file to refer to when the jo launches on the linux box..

Right: on the Options tab there is the "for UNIX. source user's profile" check box.  I want this checked on as there is a lot of setup the bash_profile does for the job. The problem is that is it noisy and all its output get put into the variable.

I am experimenting redirecting the ouput of the command lines in bash_profile to /dev/null, which helps.

One more nugget: to parse the response from a command from a UNIX/Linux agent for a specific string and store that in a variable, I followed Rami's advice and then had to find the string in the output.

The below example puts the first digit of a random number in the variable:

Job Command:

bash -c

Command Parameters:

"'echo' Random number is $RANDOM | perl -ple 's/.*Random number is (\d{1}).*/\1/'"

Note that your command itself (in this case "echo") cannot be put in the Command box, otherwise TES does not interpret the Command Parameters correctly.  So you need to set the Command to "bash -c" (run the command in the parameter string), and enter your command and parameters within double quotes in the Command Parameters, with the command being run (in this case "echo") in single quotes at the beginning.

(I also had to make my .bash_profile run without any output to avoid it being prefixed to the variable value.)

Hope this helps,

Martin.