Page 1 of 1

Calling Unix script in Datstage Transformer

Posted: Thu Jan 03, 2013 6:59 am
by sid19
Hi,

Can we call Unix script in Datastage job for every output row of a Transformer stage or is there any way to call Unix script for every output row of any stage?

Thanks,
Sid

Posted: Thu Jan 03, 2013 7:28 am
by chetan.c
There is an external filter stage where you can use unix commands which operate on each row.
Not sure if you can call a script there.

Posted: Thu Jan 03, 2013 8:22 am
by chulett
That would be a PX answer. For a Server job, create a routine that leverages DSExecute() and call that in your transformer.

Posted: Thu Jan 03, 2013 8:35 am
by sid19
Hi Chulett,

Can you please explain what do you mean by " a routine that leverages DSExecute()"

Posted: Thu Jan 03, 2013 8:42 am
by chulett
You write a custom routine in DataStage BASIC that calls the DSExecute() function, it allows you to call operating system commands which includes scripts. In a transformer, this can be called for every row.

Posted: Thu Jan 03, 2013 12:01 pm
by rameshrr3
This is a very simple routine executes a Unix command which is passed to it, and returns the output of the command. It Can be called from a transformer - but the command output needs to be formatted in the way you need ( watch out for field and item seperators, newlines etc)

Input Arguments:
Arg1: command to be executed

Return:
Ans: output of command

Code: Select all

Command = Arg1

Call DSExecute("UNIX", Command, Output, SystemReturnCode)

If SystemReturnCode Then
      Message = "Unable to execute command -  " : Command : " Output - " : Output
      Call DSLogFatal(Message,"ExecUNIXcmd")
      Ans = Message
End


Ans=Output

Posted: Thu Jan 03, 2013 1:58 pm
by ray.wurlod

Code: Select all

Ans = Message
does not accomplish anything, as it's overwritten by

Code: Select all

Ans = Output

Posted: Thu Jan 03, 2013 2:02 pm
by chulett
Actually, it will never be executed due to the immediately preceeding call to DSLogFatal.

Posted: Thu Jan 03, 2013 11:48 pm
by chetan.c
chulett wrote:That would be a PX answer. For a Server job, create a routine that leverages DSExecute() and call that in your transformer. ...
Sorry missed the forum. :oops:

Posted: Fri Jan 04, 2013 3:22 pm
by rameshrr3
Actually that routine works while testing . but was not implemented. There's another routine that can do the trick

Arguments : UnixCmd, Seperator

Code: Select all

Command = UnixCmd;
SepDef = If IsNull(Seperator) Then @FM    Else Seperator ;
Message = ''
Call DSExecute("UNIX", Command, Output, SystemReturnCode)



If SystemReturnCode = 0 Then
      Message =  "Executed command: " :Command :"" 
      Ans = Trim(Ereplace(Output,@FM,SepDef))
End Else
      Message = "Unable to execute command -  " : Command : " Output - " : Output
      Call DSLogFatal(Message,"ExecUNIXcmd")
      Ans = Message
End

Posted: Sat Jan 05, 2013 8:57 am
by chulett
It has the same "issue" as the previous one. FYI.

Posted: Mon Jan 07, 2013 2:44 pm
by rameshrr3
It works - We've used it in a transformer to call some unix commands .

Posted: Tue Jan 08, 2013 7:36 am
by chulett
Didn't say it wouldn't or doesn't work, just pointing out that it makes no sense to have any code after a call to DSLogFatal.