how to call the shell script program through a routine

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
pongal
Participant
Posts: 77
Joined: Thu Mar 04, 2004 4:46 am

how to call the shell script program through a routine

Post by pongal »

Hi,
I need calll the file ExecFTP.sh (contains korn shell script) through a routine.
and that routine i need place it in afterjob routine and run it with by passing arguments in input values of that routine.

here i have two doubts.
1) shell script containts 6 arguments like ipadress,username,pwd,remotedir etc and these arguments i need to pass as parameter to a routine.

2). how to call this shell script file throug a routine.
tonystark622
Premium Member
Premium Member
Posts: 483
Joined: Thu Jun 12, 2003 4:47 pm
Location: St. Louis, Missouri USA

Post by tonystark622 »

1) Pass the Job Parameter in an argument to the routine. In the routine build the command in a variable something like:

Cmd = "ExecFTP.sh" : ipadress : "," : username : "," : pwd : "," : remotedir : "," : JobParameterArg : "," : Arg6

where the arguments on the command line are the Argument Names for the arguments passed in to the routine. In this example JobParameterArg is the argument for this routine where you passed in the Job Parameter you said you needed to pass in.

2) You can use the DSExecute function to call a Unix shell script (provided, of course, that your DataStage server is running on Unix). I don't remember the exact syntax, but it's something like:

DSExecute("UNIX", Cmd, CmdOutput, RetCode)

where Cmd is the variable containing the command you built in 1); CmdOutput is a variable to hold any output generated by your command; and RetCode is a variable to hold the return code from the command. You can examine the CmdOutput and RetCode variables after DSExecute returns to see what ouput and return codes your command generated.

Good Luck,
Tony
pongal
Participant
Posts: 77
Joined: Thu Mar 04, 2004 4:46 am

Post by pongal »

hi tony,
my intention is
already ExecFTP.sh contains the following parameters
ip=$1
username=$2
password=$3
localDir=$4
remoteDir=$5
strfilename=$6
the above parameters i need to call from a afterjobroutine as 6 input arguments.
here MY routine is like EXFTP001(ip,username,pwd,localdir,remotedir,strfilename)

in this routine how to call ExecFTP.sh file so that it should read all the contents and transfers the file from one server to another server location.
tonystark622
Premium Member
Premium Member
Posts: 483
Joined: Thu Jun 12, 2003 4:47 pm
Location: St. Louis, Missouri USA

Post by tonystark622 »

pongal

If you filled out the information correctly in your first message, I think you have a problem. It says that you're running DataStage on Windows. If that's the case, you can't run a UNIX shell script in Windows unless you load some kind of other layer like SIGWIN or something similar.

Other than that, put your routine name and arguments in the after job routine. In the routine itself, you pretty much do the things I mentioned. You have to add a parameter to the routine for the Job Parameter that you wish to pass in, assuming it's NOT one of the six you listed. Then build the command like I demonstrated and call DSExecute. You may have to look up DSExecute to find the exact syntax, as the line I put in my email was done off the top of my head.

good luck,
Tony
pongal
Participant
Posts: 77
Joined: Thu Mar 04, 2004 4:46 am

Post by pongal »

this is the routine i am writing down here
************************************************************
**does the following things
**1) write a sequential file containing date,inputrowcount and output **rowcount
**2) calling shell script file
*************************************************************
#INCLUDE DSINCLUDE JOBCONTROL.H
#INCLUDE DSINCLUDE DSJ_XFUNCS.H
OPENSEQ '/apps/Ascential/Projects/TIP/ACRExtract.txt' TO SeqFilePtr THEN NULL ELSE NULL
WEOFSEQ SeqFilePtr ;
INPUTDATE = OConv(@DATE,"D2/")
INROWCOUNT = DSGetLinkInfo(DSJ.ME,"BASIC_TRNS_F0901","In_FO901_SrcData", DSJ.LINKROWCOUNT)
LdRowCount = DSGetLinkInfo(DSJ.ME,"BASIC_TRNS_F0901","Out_AccountFile", DSJ.LINKROWCOUNT)
WRITESEQ "Date: ":INPUTDATE ON SeqFilePtr ELSE CALL DSLogFatal("Date failed",'\')
WRITESEQ "RecordCount: ":INROWCOUNT ON SeqFilePtr ELSE CALL DSLogFatal("Extract rowcount is failed",'\')
WRITESEQ "OutputCount: ":LdRowCount ON SeqFilePtr ELSE CALL DSLogFatal("Load rowcount is failed",'\')
CLOSESEQ SeqFilePtr

Call DSExecute("UNIX", 'chmod +x' :"/apps/Ascential/Projects/TIP/ExecFTPScript.sh": Cmd,output,SystemReturnCode)

ErrorCode = 0 ;* set this to non-zero to stop the stage/job
*************************************************************
This routine AccountExtract(Cmd) in after job routine in server job properties. i compiled it its working fine.

in server job properties----

i given routine's input value(i:e for the argument Cmd)
in afterjobtoutine like this

'10.89.12.51':'a089TI':'Etl':'/apps/Ascential/Projects/GATE/':'/apps/global/':"AccountExtract.txt"

job is running fine
but, afterjob routine is not working and not giving any error message.
i could not able to ftp the files from one server to another server.

Shell Script AccountExtract.sh
************************************************************
#!/bin/ksh
#Checking for valid no of input parameters

if [ $# -ne 6 ]
then
echo "Some Command Line parameters are missing. Usage is as follows:"
echo "ExecFTPScript.sh <IP address> <username> <password> <dir path on local machine> <dir path on remote machine> <filename format of files for FTP>"
exit 1
fi

echo "Script call format is ok with all parameters present."

ip=$1
username=$2
password=$3
localDir=$4
remoteDir=$5
strfilename=$6
tmpLogFile="ftplog"

echo "Script called with following parameters:"
echo "FTP Address : "$ip
#echo "Username: "$username
#echo "Password : "$password
echo "Local Directory : "$localDir
echo "Remote Directory : "$remoteDir
echo "Format of files for FTP : "$strfilename


echo "\nStarting FTP process..."

#Open FTP Connection
ftp -nvi $ip >$localDir/$tmpLogFile << EOD
echo "ftp -nvi $ip >$localDir/$tmpLogFile"

#Authenticate the user
user $username $password

#Change FTP mode to binary
bin
echo "mode changed to binary"
#Change local directory
lcd $localDir

#Change remote directory to directory where source files are present
cd $remoteDir
echo pwd
echo "Directory changed ..."
#FTP all files to local directory with the specified filename format
echo $remoteDir
mget $strfilename
echo $strfilename
echo `wc -l $localDir/$strfilename`

#Close FTP connection
close
bye
EOD

#Determine if FTP is complete
Flag=`cat $localDir/$tmpLogFile | grep -c "Transfer complete"`
NoFileFlag=`cat $localDir/$tmpLogFile | grep -c "No such file"`
echo $Flag
#Delete files at remote location on successful FTP
if [ $Flag -ge 1 ]
then
ftp -nvi $ip >$localDir/$tmpLogFile << EOF
user $username $password
cd $remoteDir
mdel $strfilename
close
bye
EOF
fi

#If there are no files on FTP server then also FTP is successful
if [ $NoFileFlag -ge 1 ]
then
Flag=1
fi

#Delete the FTP log file
#rm -f $localDir/$tmpLogFile

#Specifying exit status
if [ $Flag -ge 1 ]
then
echo "\nSuccessfully completed FTP process!"
exit 0
else
echo "\nFTP process failed!"
exit 1
fi
**************************************************************


please check the above code and help me out is there any thing i missed out.


Thanks
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

It looks like you just do a chmod command and never execute the command.

Code: Select all

Call DSExecute("UNIX", 'chmod +x' :"/apps/Ascential/Projects/TIP/ExecFTPScript.sh": Cmd,output,SystemReturnCode) 
Even in this I think you need a space between +x and the path. I think Tony's solution was close.

Code: Select all

ipaddress = '1.1.1.1'
username = 'Whatever'
pwd = 'Whatever'
localdir  = 'Whatever'
remotedir  = 'Whatever'
Cmd = :"/apps/Ascential/Projects/TIP/ExecFTPScript.sh " : ipadress : " " : username : " " : pwd : " " : localdir : " " : remotedir : " " : strfilename
DSExecute("UNIX", Cmd, CmdOutput, RetCode) 
Mamu Kim
tonystark622
Premium Member
Premium Member
Posts: 483
Joined: Thu Jun 12, 2003 4:47 pm
Location: St. Louis, Missouri USA

Post by tonystark622 »

Thanks, Kim. I thought I was on the right track, but I was in a hurry when I wrote it and didn't have time to do it on the computer. Thanks for looking this over.

Tony
Post Reply