Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass Return Codes Outside Aspect Script

Status
Not open for further replies.

corn09

Programmer
Mar 10, 2003
2
US
I am in the process of automating an Aspect Script. I am using an outside scheduling tool (Tivoli Workload Scheduler) and have gotten the scheduler to kick off the script and complete the upload of a file successfully. My question is how can I pass return codes from the script to the scheduler to determine if the upload was successful or unsuccessful.

The only examples for various errors are to use user messages. Since the script needs to be fully automated a user message will not be of help. Is there a way to pass a return code?

Examples of errors:
Transmission failed
Connection failed (wrong password or phone number)
No file to transfer

With this errors how can I exit out of the script and exit out of ProComm successfully but at the same time let the scheduler know that the transmission failed with one of the above errors?


Also, the connection log within ProComm is very limited in the details it provides. Is there a way to have this log state the reasons for the failed transmission (even if the script has successfully exited)? Is there another log I could use?
 
Q. How can I pass return codes from the script.

A. You can set an environment variable with your error message using the putenv command.
i.e. putenv "ERRORMSG=Transmission Failed"
Alternatively, you can write the error message to a text file using the fopen/fputs commands.


Q. Is there a way to have the connection log state the reasons for the failed transmission.

A. Have your script specify the reason to the status line using statmsg, and then under Procomms System Options, check the box that says "Write status line message to Connection Log"
 
Thanks for the help! I was able to get a more detailed log now using statmsg.

As for my questions regarding passing a return code, I need some more help. The scheduler I am using is kicking off a batch script (.cmd) which invokes my Aspect script. Is there a way to pass the exit code (return code) back to the batch script? Or can I set (and pass) the %ERRORLEVEL% from within the script? I am still confused with how putenv works in passing a value back to the batch script. Thanks again for the help.
 
Unfortunately, I do not know of any way of passing return codes (ERRORLEVELS) back to an executing batch script. However, a workaround for your problem could be to create a flag file for your error level and then have your batch script check for the existance of this flag file. See the examples below.

Example of Batch Script "errorlevel.cmd"
Code:
@echo off

..\Programs\pw5.exe errorlevel.wax

if exist flag1.err goto EL1
if exist flag2.err goto EL2
if exist flag3.err goto EL3
if exist flag4.err goto EL4

echo ErrorLevel = 0
goto End

:EL1
echo ErrorLevel = 1
goto End

:EL2
echo ErrorLevel = 2
goto End

:EL3
echo ErrorLevel = 3
goto End

:EL4
echo ErrorLevel = 4
goto End

:End

Example of Procomm Script "errorlevel.was"
Code:
proc main
integer ErrorLevel = 0              ;Define integer for error level.

delfile "flag1.err"                 ;Delete all flag files
delfile "flag2.err"                 ;
delfile "flag3.err"                 ;
delfile "flag4.err"                 ;

ErrorLevel = 3                      ;This sets error level to 3

if ErrorLevel == 1                  ;Create flag file for your error level
   fopen 0 "flag1.err" create text  ;
elseif ErrorLevel == 2              ;
   fopen 0 "flag2.err" create text  ;
elseif ErrorLevel == 3              ;
   fopen 0 "flag3.err" create text  ;
elseif ErrorLevel == 4              ;
   fopen 0 "flag4.err" create text  ;
endif                               ;
fclose 0                            ;Save and close flag file

pause 3                             ;Allow time to create flag file
pwexit                              ;before exiting
endproc
 
NOTE: For the above example to work, you will need some sort of delay in your batch script after it runs your procomm script. This delay is to ensure that the Procomm script has completed all of it's tasks before the batch script checks for the existance of the flag file.
 
Another way to write to file that would be accessible back to your Tivoli scheduler script would be to use an .ini file. ProComm uses two commands profilerd & profilewr to access individual pieces of data from the specially structured windows ini text file.

Code:
.
string System_ck, stat_ini, stat_ck, reason_ck
string date_ck, time_ck
integer num_attempt
stat_ini = c:\data\status\System_Daily.ini
.
.(set up loop to loop thru systems)
System_ck = System_1
profilerd stat_ini, System_ck, "Attempts" num_attempt
num_attempt++
profilewr stat_ini, System_ck, "Attempts" num_attempt
. (do daily dumps)
stat_ck = "SUCCESS"
reason_ck="Completed"
profilewr stat_ini System_ck "STATUS" stat_ck
.

Code is just fragments to get the idea across.
Note that I did not take care of initializing the ATTEMPTS or other particulars. If you'd like a better example let me know. The nice thing about INI files is you don't have to worry about open / close of file and status will be available even as the script continues but external access while the script is running could cause the script to fail to write I would guess.

ini file might look like:

System_Daily.ini
----------------------
[System_1]
ATTEMPTS=1
STATUS=SUCCESS
REASON=Completed
DATE=03/14/03
TIME=08:23:56

[System_2]
ATTEMPTS=1
STATUS=FAILED
REASON=Timed out during line data dump.
DATE=03/14/03
TIME=08:34:17

If Tivoli scheduler does not have the capability to access .INI files directly but does have the ability to open text files then it would be neccessary to simulate the profilerd command's function using script code for Tivoli.


Another option to get data out of Procomm to your scheduler program would be to set up a DDE link between Tivoli scheduler and Procomm --- if Tivoli supports DDE.
I am just now planning on getting my feet wet with DDE so I am not the best source of info on that subject.


Hope I was some help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top