Wrapped stage

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
hhh
Participant
Posts: 86
Joined: Tue Aug 02, 2005 7:39 am

Wrapped stage

Post by hhh »

Hello friends,

Have created one shell script which has two parameters.
Have requirement to call this shell script using Wrapped stage.
please share your ideas to design this job,like what are stages required ? etc.

Thanks & Regards
Hman
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Do you want to invoke this script once, or once for every row processed?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
hhh
Participant
Posts: 86
Joined: Tue Aug 02, 2005 7:39 am

Post by hhh »

Hi,

I want to pass parameters like pathname and retention period, and if i enter retention period, so file which are older than retention period should be removed from particular path.
My requirement is to enter dynamically pathname and retention period.

Thanks & regards
Hman
ray.wurlod wrote:Do you want to invoke this script once, or once for every row processed?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You avoided the question. Do you want to invoke this shell script once, or once for every row processed in a job? The answer to your original question depends on your answer to this one.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
hhh
Participant
Posts: 86
Joined: Tue Aug 02, 2005 7:39 am

Post by hhh »

I want to invoke shell script once
ray.wurlod wrote:You avoided the question. Do you want to invoke this shell script once, or once for every row processed in a job? The answer to your original question depends on your answer to this one.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Then all you need is a before-job subroutine executing ExecSH with your script's path and command line arguments (all can be job parameter references) in the Input Values field.

A Wrapped stage would execute the script for every row processed by the job.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
hhh
Participant
Posts: 86
Joined: Tue Aug 02, 2005 7:39 am

Post by hhh »

Hi Ray,

In job we dont want to use before-job subroutine or after-job subroutine,we need to make generic solution. so how can we achieve
solution without any subroutines ?
ray.wurlod wrote:Then all you need is a before-job subroutine executing ExecSH with your script's path and command line arguments (all can be job parameter references) in the Input Values field.

A Wrapped stage would execute the script for every row processed by the job.
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
You can also wrap the script call in a DS Routine and call it in a before/after routine or as a routine activity in a sequence job.
Having this in a Routine sounds generic to me.

IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
Ultramundane
Participant
Posts: 407
Joined: Mon Jun 27, 2005 8:54 am
Location: Walker, Michigan
Contact:

Post by Ultramundane »

Could you use the External Target Stage. The External Stage will call your script one time and you will need to process standard input in a loop. You can also invoke your script with command line arguments. I typically use awk to process the contents, but you could also use just korn shell and not any other utilities.

In your script, just do a cat - to redirect standard input passed to the shell to whatever command you would like. This command could be awk, while, for, a block, etc. You may want to format your data so that it contains a field seperator. You can set IFS (ksh) or FS (awk) to that value. This can make processing the data much easier.

Below is a really simple example of script which accepts a delimiter and filename for command line arguments. Input is passed in through standard input/input redirection into the program.

Code: Select all

#!/bin/ksh

#################################################################################################
##
## Author: Ryan Putnam
##
#################################################################################################

## SOURCE ENVIRONMENT
. ~/.dsadm

## TRAP FOR EXIT AND ABNORMAL TERMINATION
trap "rm -f ${BTMP}/*.$$ >/dev/null 2>&1;rm -f ${BTMP}/*$$.doc >/dev/null 2>&1" EXIT INT TERM QUIT

###########
## USAGE ##
###########
F_USAGE()
{
   print -u2 "ERROR: ${1}"
   shift

   print -u2 "USAGE: ${1##*/} -D '<Delim>'"
   print -u2 "USAGE: ${1##*/} -F '<File>'"
   print -u2 "USAGE: ${1##*/} -H '<HELP>' -h '<HELP>'"
   exit 10
}

## Lists Usage Information
if [[ "${1}" = "-h" || "${1}" = "-H" ]]; then
   F_USAGE "$0"
fi

## MAP INPUT TO VARIABLES
while getopts D:F: opt
do
   case $opt in
   (D) AFS="$OPTARG" ;;
   (F) FILE="$OPTARG" ;;
   (*) F_USAGE "$0" ;;
   esac
done

####################
## VALIDATE PARMS ##
####################
[[ -z "${AFS}" ]] && F_USAGE "You must specify a delimiter"
[[ -z "${FILE}" ]] && F_USAGE "You must specify a file"

##############
## MAINLINE ##
##############
cat - \
| awk -vAFS="${AFS}" -vFILE="${FILE}" 'BEGIN{FS=AFS;OFS=AFS;}
{
      print $0 >FILE;
}'

exit 0
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You don't need to create a before/after subroutine. Use ExecSH, which is supplied with DataStage. I believe that this is sufficiently generic a solution.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
hhh
Participant
Posts: 86
Joined: Tue Aug 02, 2005 7:39 am

Post by hhh »

Hi,

Tried to call unix script with external target stage however when i specify pathname to call unix script in destination programme i got warning like
pathname/del.sh not execute and error like export failed.
with pathname i have specified two arguments also

can u please suggest on this issue ?

Thanks
Hman


Ultramundane wrote:Could you use the External Target Stage. The External Stage will call your script one time and you will need to process standard input in a loop. You can also invoke your script with command line arguments. I typically use awk to process the contents, but you could also use just korn shell and not any other utilities.

In your script, just do a cat - to redirect standard input passed to the shell to whatever command you would like. This command could be awk, while, for, a block, etc. You may want to format your data so that it contains a field seperator. You can set IFS (ksh) or FS (awk) to that value. This can make processing the data much easier.

Below is a really simple example of script which accepts a delimiter and filename for command line arguments. Input is passed in through standard input/input redirection into the program.

Code: Select all

#!/bin/ksh

#################################################################################################
##
## Author: Ryan Putnam
##
#################################################################################################

## SOURCE ENVIRONMENT
. ~/.dsadm

## TRAP FOR EXIT AND ABNORMAL TERMINATION
trap "rm -f ${BTMP}/*.$$ >/dev/null 2>&1;rm -f ${BTMP}/*$$.doc >/dev/null 2>&1" EXIT INT TERM QUIT

###########
## USAGE ##
###########
F_USAGE()
{
   print -u2 "ERROR: ${1}"
   shift

   print -u2 "USAGE: ${1##*/} -D '<Delim>'"
   print -u2 "USAGE: ${1##*/} -F '<File>'"
   print -u2 "USAGE: ${1##*/} -H '<HELP>' -h '<HELP>'"
   exit 10
}

## Lists Usage Information
if [[ "${1}" = "-h" || "${1}" = "-H" ]]; then
   F_USAGE "$0"
fi

## MAP INPUT TO VARIABLES
while getopts D:F: opt
do
   case $opt in
   (D) AFS="$OPTARG" ;;
   (F) FILE="$OPTARG" ;;
   (*) F_USAGE "$0" ;;
   esac
done

####################
## VALIDATE PARMS ##
####################
[[ -z "${AFS}" ]] && F_USAGE "You must specify a delimiter"
[[ -z "${FILE}" ]] && F_USAGE "You must specify a file"

##############
## MAINLINE ##
##############
cat - \
| awk -vAFS="${AFS}" -vFILE="${FILE}" 'BEGIN{FS=AFS;OFS=AFS;}
{
      print $0 >FILE;
}'

exit 0
Ultramundane
Participant
Posts: 407
Joined: Mon Jun 27, 2005 8:54 am
Location: Walker, Michigan
Contact:

Post by Ultramundane »

Make sure that you mark the script as executable and readable.

I setup the stage as follows.

Input -> Properties -> Target -> Destination Program
/Work/Ascential/script/example_awk.ksh -D"?" -F"/Work/Ascential/tmp/mystuff.txt"

Input -> Properties -> Target -> Target Method
Specific Program(s)

Input -> Format -> Field Defaults -> Delimiter
?
Note: I set to a "?" because I passed -D"?" to the program.

Input -> Format -> Field Defaults -> Quote
none
Note: I set to none to save space and because this property is useless to me.
hhh
Participant
Posts: 86
Joined: Tue Aug 02, 2005 7:39 am

Post by hhh »

Hi Ultramundane,
I setup the stage as follows :
Input -> Properties -> Target ->Destination Program
pathname/del.sh pathname retentionperiod
here after pathname/del.sh ,pathname and retentionperiod are two arguments which i want to pass in shell script.
Input -> Properties -> Target -> Target Method
Target method: specific programs
Input->format->field defaults
none.
have setup properties like this,still i am getting same warning and error.

please advise on same

Thanks
Hman
Ultramundane wrote:Make sure that you mark the script as executable and readable.

I setup the stage as follows.

Input -> Properties -> Target -> Destination Program
/Work/Ascential/script/example_awk.ksh -D"?" -F"/Work/Ascential/tmp/mystuff.txt"

Input -> Properties -> Target -> Target Method
Specific Program(s)

Input -> Format -> Field Defaults -> Delimiter
?
Note: I set to a "?" because I passed -D"?" to the program.

Input -> Format -> Field Defaults -> Quote
none
Note: I set to none to save space and because this property is useless to me.
Post Reply