Here's a sample routine which I have used to FTP files and log all error messages and then continue as per my requirement. But, it is on Windows. I made some changes as to suit Unix but suit yourselves and make changes to run it in your environment as per your requirements. From what I understand of your requirement you will only need the first half of this routine and will have to add some more Arg's (paramerters) in your case.
* FTPfiles
*---------------------------------------------------------------------
* Description: FTP's file(s) to a remote server.
*---------------------------------------------------------------------
* Written by: Kris
*---------------------------------------------------------------------
$INCLUDE DSINCLUDE JOBCONTROL.H
Deffun DSRMessage(A1, A2, A3) Calling "*DataStage*DSR_MESSAGE"
Equate RoutineName To "FTPfiles"
Details = ''
NewDetails = ''
Arg1 = FILEPATH
Arg2 = SERVERNAME
Arg3 = USERID
Arg4 = PASSWORD
Arg5 = FILENAME
Arg6 = CMD
Arg7 = FILECOUNT
InputArg = CMD :FILEPATH: '&&' :FILENAME:' ':SERVERNAME:' ':USERID:' ':PASSWORD
*---------------------------------------------------------------------
* If InputArg is empty, log a Warning-type message and return
* ErrorCode = 1 (job will abort if called as Before routine).
*---------------------------------------------------------------------
If Trim(InputArg) = "" Then
Message = DSRMessage("DSTAGE_TRX_E_0011", "No command to execute.", "")
GoTo ErrorExit
End
*----------------------------------------------------------------------
* Else, call support routine that executes a UNIX command.
*----------------------------------------------------------------------
Call DSExecute("UNIX", InputArg, Output, SystemReturnCode)
*------------------------------------------------------------------------
*Read the contents of the .bat.log file and write them to a sequential
*file .
*------------------------------------------------------------------------
OpenSeq FILEPATH:'\':FILENAME:".log" To FileVar Else
Call DSLogWarn("Cannot open "FILEPATH:'\':FILENAME:".log" , "Cannot Open the log file")
*GoTo ErrorExit
End
loop
ReadSeq NewDetails From FileVar Else Exit ;
Details=Details : NewDetails;
repeat
*------------------------------------------------------------------------
* Log any and all output as an Information type log message,
* unless system's return code indicated that an error occurred,
* when we log a slightly different Warning type message and set
* ErrorCode = 1 (job will abort if called as Before routine).
*------------------------------------------------------------------------
If Trim(Output) <> "" Then
Message = DSRMessage("DSTAGE_TRX_I_0005", "<L>*** Output from command was: ***<L>", ""):Output:Details
End Else
Message = DSRMessage("DSTAGE_TRX_I_0006", "<L>*** No output from command ***", "")
End
If SystemReturnCode = 0 Then
Message = DSRMessage("DSTAGE_TRX_I_0039", "Command executed successfully.", ""):Message: Details
Call DSLogInfo(Message, RoutineName)
End Else
Message = DSRMessage("DSTAGE_TRX_I_0040", "Error when executing command. ", ""):Message
GoTo ErrorExit
End
*--------------------------------------------------------------------------
*Read the contents of the .bat.log file and search for strings which
*describe any kind of error messages. If found, then log those
*messages as Warning type log message.
*--------------------------------------------------------------------------
Count1 = Count(Details, "File not found")
Count2 = Count(Details, "Failed")
Count3 = Count(Details, "Please login with USER and PASS")
Count4 = Count(Details, "used by another process")
Count5 = Count(Details, "Transfer complete")
If Count1>= 1 Then
Call DSLogWarn("Cannot find file to be ftp'd " , "File not Found")
End
If Count2 >= 1 Then
Call DSLogWarn("Process failed while ftp'ing files")
End
If Count3 >= 1 Then
Call DSLogWarn("Invalid username or password", "Login failed")
End
If Count4 >= 1 Then
Call DSLogWarn("The process cannot access the file because it is being used by another process", "Used by another process")
End
*-------------------------------------------------------------------
*Read the .bat.log file and search for string "Transfer Complete"
*in order to determine the number of files transferred(ftp'd)
*successfully. If all the files have not been transferred, the
*log a warning message with total number of files transferred.
*-------------------------------------------------------------------
If Count5 = FILECOUNT Then
Call DSLogInfo(" All the files have been transferred successfully", " Transfer Completed")
End
Else
Call DSLogWarn(" All the files have not been transferred successfully. ":"Num of files Transferred =": Count5, "Transfer Incomplete")
GoTo ErrorExit
End
CloseSeq FileVar
*-----------------------------------------------------------------------
* Exit with no error.
*-----------------------------------------------------------------------
ErrorCode = 0
GoTo NormalExit
*-----------------------------------------------------------------------
* Exit with error, logging warning message first.
*-----------------------------------------------------------------------
ErrorExit:
Call DSLogWarn(Message, RoutineName)
ErrorCode = 1
NormalExit:
Ans=ErrorCode
From your post and the script it looks that your OS is UNIX i.e. the Datastage server is installed on Unix. I don't understand when you say you want to try on a windows machine. I take it that your client is installed on windows and that is what you meant. Anyways, if you check the Basic manual for DSExecute, it answers your purpose. I would need some time before I can explain it stepwise. I hope you figure it out by the time I come back to you with a detailed explanation.
In BTW, can you verify how you are passing the path to the script you have written in Execute Command Stage(Can you post the text from the command window in your stage). That question is still unanswered.
* FTPfiles
*---------------------------------------------------------------------
* Description: FTP's files to a server.
*---------------------------------------------------------------------
* Written by:
*---------------------------------------------------------------------
$INCLUDE DSINCLUDE JOBCONTROL.H
Deffun DSRMessage(A1, A2, A3) Calling "*DataStage*DSR_MESSAGE"
Equate RoutineName To "FTPfiles"
*Arg1 = FILEPATH Path where your script resides.
*Arg2 = SERVERNAME Remote Server Name
*Arg3 = USERID
*Arg4 = PASSWORD
*Arg5 = FILENAME Name of your script
*Arg6 = CMD Command to change directories. "cd" in most cases *and "pushd" when you are dealing with UNC path names.
*Arg7 = REMOTEPATH
*Arg8 = REMOTEFILE
*Arg9 = LOCALPATH
*Arg10= LOCALFILE
*Arg11= LOGPATH
InputArg = CMD :FILEPATH: '&&' :FILENAME:' ':SERVERNAME:' ':USERID:' ':PASSWORD:' ':REMOTEPATH:' ':REMOTEFILE:' 'LOCALPATH:' ':LOCALFILE:' ':LOGPATH
*---------------------------------------------------------------------
* If InputArg is empty, log a Warning-type message and return
* ErrorCode = 1 (job will abort if called as Before routine).
*---------------------------------------------------------------------
If Trim(InputArg) = "" Then
Message = DSRMessage("DSTAGE_TRX_E_0011", "No command to execute.", "")
GoTo ErrorExit
End
*----------------------------------------------------------------------
* Else, call support routine that executes a UNIX command.
*----------------------------------------------------------------------
Call DSExecute("UNIX", InputArg, Output, SystemReturnCode)
*------------------------------------------------------------------------
* Log any and all output as an Information type log message,
* unless system's return code indicated that an error occurred,
* when we log a slightly different Warning type message and set
* ErrorCode = 1 (job will abort if called as Before routine).
*------------------------------------------------------------------------
If Trim(Output) <> "" Then
Message = DSRMessage("DSTAGE_TRX_I_0005", "<L>*** Output from command was: ***<L>", ""):Output
End Else
Message = DSRMessage("DSTAGE_TRX_I_0006", "<L>*** No output from command ***", "")
End
If SystemReturnCode = 0 Then
Message = DSRMessage("DSTAGE_TRX_I_0039", "Command executed successfully.", ""):Message
Call DSLogInfo(Message, RoutineName)
End Else
Message = DSRMessage("DSTAGE_TRX_I_0040", "Error when executing command. ", ""):Message
GoTo ErrorExit
End
*-----------------------------------------------------------------------
* Exit with no error.
*-----------------------------------------------------------------------
ErrorCode = 0
GoTo NormalExit
*-----------------------------------------------------------------------
* Exit with error, logging warning message first.
*-----------------------------------------------------------------------
ErrorExit:
Call DSLogWarn(Message, RoutineName)
ErrorCode = 1
NormalExit:
Ans=ErrorCode
First of all, create a Routine in the DSManager and use the above code in the Routine. Don't forget to declare all the arguments I have defined in the above routine on the Arguments tab in the Routine. I have explained what each argument is hoping you can figure out which I didnt explain.Compile and test the routine in your manager. Also use an exit command in your script so that command window doesn't hang in there in the background after executing the scripts. Else, everytime you test the routine from manager, your Manager hangs since the command window is open in the background.Now, in the Job Sequence, use a RoutineActivity stage.Call this routine in there. Now, for the arguments in the routine pass all the parameters you have defined in the Job sequence when you were using the ExecuteCommand Stage. Then run the Job and see if everything is working fine and let us know.
Kris,
Yes,I meant to say that my server is on Unix and client is installed on Windows.Sorry if i have confused you.Thanks for the detailed explanation.
I will follow the process which you mentioned in last post and let you know how it works.
Thats great. I still wonder why it didn't work with Execute Command Activity. I would also recommend you enhance the routine such that any error message can be logged in the routine instead of routine just failing. A look at my earlier routine will give you an idea.