Link to home
Start Free TrialLog in
Avatar of xzay1967
xzay1967

asked on

Please explain script and how to change

Hi all I am working on some ftp scripts but need a little help understanding a syntax.
 I like to keep the scripts clean and don't want to use a bunch of If else lines. I want to use the exit /b  and exit /b 1 more effectively, but need some guidance. Here is a sample of how I used it. Can someone please explain simply as possible the difference between exit /b and exit /b 1
if exist "D:\APTsx\apt_parent_article_ss_%NewDate%.csv" echo Unprocessed file found >>%TRACEFILE1%
if exist "D:\APTsx\apt_parent_article_ss_%NewDate%.csv" (GOTO:MOVE_FILE_TO_DESTINATION) ELSE (GOTO:GET_FILE)
>>%TRACEFILE1% echo Starting FTP GET_FILE PROCESS                               
"E:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt.com" ftpscrpt -f "%SCPFILE1%"
COPY %TRACEFILE1% %EMAILFOLDER%\APTSX_ERROR_LOG.TXT
IF EXIST %EMAILFOLDER%\APTSX_CONNECTION_TRIGGER.TXT (
CALL "%EMAILEXE%" APT_Shrink_Spoilage_ERROR
EXIT /b 1
)
IF EXIST %EMAILFOLDER%\APTSX_NO_FILE.TXT (GOTO:NOTIFY_EMAIL) ELSE (
GOTO:MOVE_FILE_TO_DESTINATION
EXIT /b
)
:: BUILDING IPSWITCH SCRIPT FOR FTP PROCESS
:MOVE_FILE_TO_DESTINATION
>>%TRACEFILE2% echo Starting MOVE_FILE_TO_DESTINATION PROCESS

Open in new window

SOLUTION
Avatar of SStory
SStory
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xzay1967
xzay1967

ASKER

I have to admit, I am so lost with all this scripting stuff, lol. What I am trying to achieve is the following:
if xyz happens, do abc, but do not go to the next subroutine.
If xyz does not happen, go to the next subroutine. I guess I can just use the goto command and save myself the headache. I was just trying to avoid writing tons of if xyz, do or goto abc.
Well,
You don't really need the Else:

IF EXIST %EMAILFOLDER%\APTSX_NO_FILE.TXT (GOTO:NOTIFY_EMAIL) ELSE (
GOTO:MOVE_FILE_TO_DESTINATION
EXIT /b

Open in new window


This could be written as follows:
]IF EXIST %EMAILFOLDER%\APTSX_NO_FILE.TXT  GOTO NOTIFY_EMAIL
GOTO MOVE_FILE_TO_DESTINATION

Open in new window


Either way, unless there is a return of some sort it should never get to the EXIT command.
Why do you need exit codes? Are you using the results in another script or app?  If not a simple
goto end_all

and a label at the bottom

:end_all

would be fine.
The problem I ran into that brought me to this point is that I have a script that was not going to the next subroutine even if the error did not occur. Here is the script as is

"E:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt.com" ftpscrpt -f "%SCP_FILE1%"
COPY %TRACEFILE1% %EMAIL_FOLDER%\APT_LOTTERY_ERROR_LOG.TXT
IF EXIST %EMAIL_FOLDER%\CONNECTION_ERROR_TRIGGER.TXT CALL "%EMAIL_EXE%" APT_LOTTERY_ERROR
IF EXIST %EMAIL_FOLDER%\FILE_GET_ERROR_TRIGGER.TXT (
	CALL "%EMAIL_EXE%" APT_LOTTERY_FILE_GET_ERROR
	EXIT /b
) >>"%LOGFILE%"
GOTO:MOVE_FILE_TO_DESTINATION

REM
:MOVE_FILE_TO_DESTINATION
>%SCP_FILE2%  echo  TRACE %TRACEFILE2%

Open in new window



***********************
The job ran, the error file was not created, yet, the script did go to the Move_file_to_destination subroutine. The job would exit at the Exit /b command. I tried it with Exit /b 1, it did the same thing. I thought maybe I need to actually put the command Else into the syntax to make it go to the next subroutine, it still exit. Oddly I have other scripts that have the exit /b and exit /b 1 and they run fine, so not sure where I went wrong here.
No not calling any other scripts, I just thought I could use Exit as a way to end the if else loop so that script will continue or exit fine. But if you recommend that I get rid of the exit and use goto instead, then so be it.
Here is a copy of one that works using the exit code
>>%LOGFILE% echo Starting GET_FILE FTP PROCESS
"E:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt.com" ftpscrpt -f "%SCPFILE%"
>>%LOGFILE% TYPE %TRACEFILE%
COPY %TRACEFILE% %EMAILFOLDER%\ARMARKETING_IN_ERROR_LOG.TXT
IF EXIST %EMAILFOLDER%\ARMARKETING_IN_CONNECTION_TRIGGER.TXT (
CALL "%EMAILEXE%" ARMARKETING_IN_ERROR
EXIT /b 1
)
IF EXIST %EMAILFOLDER%\ARMARKETING_IN_FILE_TRIGGER.TXT (GOTO:NOTIFICATION_EMAIL) ELSE (
GOTO:MOVE_FILE_TO_DESTINATION
EXIT /b
)
REM
:MOVE_FILE_TO_DESTINATION
>>%LOGFILE% echo starting MOVE_FILE_TO_DESTINATION section
>>%LOGFILE% COPY D:\ARMarketing\%WAWASHIP%_%DATESTAMP%.csv %RRSRV2%\%WAWASHIP%_%DATESTAMP%.csv
SLEEP 10
:MOVE_FILE_TO_ARCHIVE
>>%LOGFILE% echo Starting MOVE_FILE_TO_ARCHIVE section
>>%LOGFILE% MOVE %WAWASHIP%_%DATESTAMP%.csv F:\ARMarketing\Archive\%WAWASHIP%_%DATESTAMP%.csv
REM
:NOTIFICATION_EMAIL
>>%LOGFILE% echo Starting NOTIFY section
COPY %TRACEFILE% %EMAILFOLDER%\ARMARKETING_IN_LOG2_COPY.TXT
If EXIST %EMAILFOLDER%\ARMARKETING_IN_FILE_TRIGGER.TXT(
CALL "%EMAILEXE%" ARMARKETING_IN_NO_FILE
EXIT /b 1

If EXIST %RRSRV2%\%WAWASHIP%_%DATESTAMP%.csv (CALL "%EMAILEXE%" ARMARKETING_IN_SUCCESS) ELSE (
CALL "%EMAILEXE%" ARMARKETING_IN_FILE_TO_RRSRV2_ERROR
EXIT /b
)

Open in new window

Sorry for the confusion, I just thought about your question regarding if I am calling another batch file. I am actually calling another program, this program is a vb program that sends an email based on the error message the job generates. Those "%emailexe%" entries in the code is a variable for the email program, the entry after the variable is a section name specific to a error type such as Armarketting_in_file_to_rrsrv2_error. This means if the file is missing on rrsrv2, sn email is sent specifying that error in the subject with the log file attached. Hope that sheds some light on what my script is does.
Yes I am using the results of another app. In the If statement, the script looks for a text file, and if it exists, then it calls the email program to send out an email based on the error type the text file addresses.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial