Use the OnStatus function to check the result of a scheduled action
To perform this we will use the OnStatus function in combination with the Getsys PRG,"ACTIONID", the Getsys PRG,"EVTINFO" and the Getsys PRG,"ACTIONSTAT".
First inside the Init Section of the Basic Script we will initiate the OnStatus trigger.
The OnStatus trigger is fired every time a scheduled action is finished. The GetSts PRG,"ACTIONID" will be used to identify the scheduled action we want to track. It must be performed directly after the execution of the scheduled action command to get the ID of the action to perform.
Once the OnStatus event fired, the Getsys PRG,"EVTINFO" will contain the ACTIONID of the scheduled action which just finished.
So we will use this info to check if the scheduled action we want to track has been finished or not.
Then using the Getsys PRG,"ACTIONSTAT" function we will check the result of the scheduled action. Possible values of ACTIONSTAT are:
- -1: in progress
- -2: ID not found
- 0: done with success
- >0: finished with error = error code
In the Init section:
ONSTATUS "GOTO ProcessActions" FTPSent_ID = 0 Type your code in the box. To create a new line within the box use SHIFT + ENTER.
Inside a user section, create the ProcessActions label:
ProcessActions: y%=Getsys PRG,"EVTINFO" If (y%= FTPSent_ID) Then Setsys PRG,"ACTIONID",y% y%=Getsys PRG,"ACTIONSTAT" If (y%=0) Then LogEvent "FTP Send OK",102 Else LogEvent "FTP Send Error (ERROR="+Str$(y%) + ")",99 Endif Endif END
This script will now automatically track the execution of all scheduled actions.
To track the result of an PutFTP command for example, use following syntax in your script:
PUTFTP "/usr/testInfo.txt", "[$dtHT $ftT $st_m1]", "adm:firstname.lastname@example.org" FTPSent_ID=Getsys PRG,"ACTIONID"