Calling Unix script in Datstage Transformer

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
sid19
Participant
Posts: 64
Joined: Mon Jun 18, 2007 12:17 am
Location: kolkata

Calling Unix script in Datstage Transformer

Post 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
Sid
chetan.c
Participant
Posts: 112
Joined: Tue Jan 17, 2012 2:09 am
Location: Bangalore

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That would be a PX answer. For a Server job, create a routine that leverages DSExecute() and call that in your transformer.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sid19
Participant
Posts: 64
Joined: Mon Jun 18, 2007 12:17 am
Location: kolkata

Post by sid19 »

Hi Chulett,

Can you please explain what do you mean by " a routine that leverages DSExecute()"
Sid
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
rameshrr3
Premium Member
Premium Member
Posts: 609
Joined: Mon May 10, 2004 3:32 am
Location: BRENTWOOD, TN

Post 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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

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

Code: Select all

Ans = Output
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Actually, it will never be executed due to the immediately preceeding call to DSLogFatal.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chetan.c
Participant
Posts: 112
Joined: Tue Jan 17, 2012 2:09 am
Location: Bangalore

Post 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:
rameshrr3
Premium Member
Premium Member
Posts: 609
Joined: Mon May 10, 2004 3:32 am
Location: BRENTWOOD, TN

Post 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
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

It has the same "issue" as the previous one. FYI.
-craig

"You can never have too many knives" -- Logan Nine Fingers
rameshrr3
Premium Member
Premium Member
Posts: 609
Joined: Mon May 10, 2004 3:32 am
Location: BRENTWOOD, TN

Post by rameshrr3 »

It works - We've used it in a transformer to call some unix commands .
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply