There have always been requirements in which you would need to run certain unix commands or shell scripts within Datastage. Although not a popular demand, its still something that can lie in the ‘good to know’ category. There are a number of different ways you can actually do this. I will try and explain the methods I have tried out.
Specifying the shell script in job properties
If you have any pre or post processing requirements that have to be run along with the job and if you have done this via a shell script, then you can specify the script in the After/Before job abort routine section , with its parameters. You should first select the ‘execsh ‘option from the drop down list to indicate that you are going to run the script.
Using the External filter stage
The external filter stage allows us to run UNIX filters during the execution of your job. Filters are programs that you would have normally used during your UNIX career. Filter programs are programs that read data from the input stream and modify it and send it on to the output stream. A filter that everyone is bound to have used is ‘grep’. Other common filters are cut, cat, grep, head, sort, uniq, perl, sh, wc and tail. The external filter stage allows us to run these commands during processing the data in the job. For eg. You can use the grep command to filter the incoming data. Shown below is a simple design.
As per the command we are filtering out data having the number 18 in it, using the grep command.
Using the sequential file stage
Although not a frequently used option, the sequential file stage does allow us to run unix filter commands inside it. In this example I have written a shell script that can be called inside the stage. The place where you have to enter the command is shown below.
The shell script written was a straight forward one that would read from the input directly
while read data; do
echo “$data, Modified by emerson” >> E:/Sample/sample.txt
#– You can add your processing logic here—–#
#———–End of script ————————-#
The output would be as below.
So the next time someone asks you if you can run a shell script though the sequential file stage, you needn’t hesitate to say YES.