Page 1 of 1

UNIX Code Reading into a Transformer?

Posted: Thu Dec 10, 2015 1:49 pm
by ScottDun
Hi!

I have a question regarding the codes that the UNIX script will push out. I input an expression ( "Field(Execute_Command_0.$CommandOutput,@FM,1) >0") into the command execute stage (of sequence job). So no for the hard part... Is there a way to link that UNIX code (mine is 1-7) into the next job?

So let's say the script says '6', I want that reading to be in the derivation of a transformer so it can out put to a column. How can I do that?

Posted: Thu Dec 10, 2015 2:12 pm
by ray.wurlod
Use a similar activity variable expression for the job parameter in the Job activity.

Posted: Thu Dec 10, 2015 2:37 pm
by ScottDun
Can you explain a little bit more. I am new to this tool and it is my first time programming. The UNIX script was created for me and I input it into a sequence job. In the job activity 1, I have the script text file filepath and the main text file it is going to attack.

In job activity 2, I set the job name and execution action to run.

The script return code is not visible and I do not know where to see it. But if you can point me to where I can see the code and then help me insert it into the transformer would be amazing.

The output file I am creating (for that specific derivation) will be If THen Else; this has Else being my default of 'A', the Then being the return code from UNIX. I do not know what the IF should be bc I do not know where to access this.

Posted: Thu Dec 10, 2015 5:17 pm
by ray.wurlod
There are activity variables that capture the command output ($CommandOutput) and the exit status ($ReturnValue) from the command (script). These are available anywhere downstream of the Execute Command activity.

So, in your Job activity, you might set the value of a job parameter to be

Code: Select all

Convert(@FM, "", MyCommand.$CommandOutput)
The Convert() function removes the trailing newline character from the command output.

Posted: Fri Dec 11, 2015 11:04 am
by ScottDun
Thanks for the response Ray, I tried buying a premium membership but site declined my card. I won't bother asking/replying until I get my membership

Posted: Fri Dec 11, 2015 1:17 pm
by ScottDun
I inserted a filepath to the Execute Comm. I need two outputs as follows :

Job Activity 1 : UNIX return code (good or bad) is going here and populating that return code into a transformer into the Job itself. The job has a column named 'PROCESS_CODE" and i want to populate it in the derivation of this column. Is this possible? (The Good output is 0 and the bad outputs are 1-7)

Job Activity 2 : If the UNIX is good (0) then Job Activity 2 is allowed to run.

I am brand new to programming and any help with coding would be great.

Posted: Fri Dec 11, 2015 1:47 pm
by chulett
As noted elsewhere, you need a Job Parameter to hold it to pass it into the job, then you can reference the #ParameterName# in a derivation. And the Sequence can easily pass the value from the Execute Command stage as input to that parameter in the Job Activity stage.

#2 is just a trigger expression that evaluates to "true" when you want the activity at the other end of the trigger to "fire".

Specifics of what you need in each expression depend on what you mean by the codes your script will "push out". As Ray noted, use $CommandOutput if you mean what the script writes to std out or use $ReturnValue if you mean they are exit status values.

Posted: Fri Dec 11, 2015 3:27 pm
by ScottDun
Yes, for the parameter, I cannot create it within the stages themselves. I made variables in the User variable Activity stage for each exit code (0-7). I do not know how to go about putting parameters within the stages so that they populate in the job activity stage ( in the job tab). How/what are the parameters to be set up within the stages?

Posted: Sat Dec 12, 2015 8:54 am
by chulett
You don't put parameters "within the stages themselves", all you need to do is add Job Parameter(s) to the job itself and then they will show up in the Job Activity stage that runs that job. Then any upstream stage can supply values to them. Best to click on the ellipsis (...) in the parameter to bring up the External Parameter Helper which will have a pick list of valid values available for use in all upstream stages.

I don't see a need for either the User Variables stage or creating multiple variables there. The former doesn't hurt, just isn't really needed. The latter should just be a single variable with the current exit code in it. IMHO.

Posted: Mon Dec 14, 2015 7:58 am
by ScottDun
I clicked the ellipsis and there is no list. It just says "All activities on the chosen Activities output".

So if you do not see the need for the user variable stage, and variables in there, what do you recommend? I have the Command execute stage with the UNIX filepath in it. From there are the two job activities and, to the first job activity, I need to insert that return code (exit 0 to exit 7) into the transformer stage of the job activity it is flowing to and the 2nd job activity is for only when the UNIX return code = exit 0.

Posted: Mon Dec 14, 2015 8:25 am
by chulett
You clicked on it where? In what stage? Sounds like there was nothing connected 'upstream' from there. I meant for you to do it from the appropriate job parameter property in the Job Activity stage so it can help you pick what to put there.

Pass the exit code directly to the parameter that needs it using the picker. And use it in the trigger expression for the second job, specifically testing for 0.

Of course, you can still use your User Variables stage to apply your transformation to the $CommandOutput dynamic array to remove the Field Mark so you only have to do it once. However, if you are using $ReturnValue for the exit status I don't believe you have to play that game.