Hi,
I have a task which runs php script.
It would be nice to have an email notification after failure/success of task and if task was executed successfully BUTT php script returns nothing or it crashes (ex. script get data from database, if there is no data for today) it should e-mail me that there was some error.
Is it possible to do?
Send e-mail notification after script success/failure
Re: Send e-mail notification after script success/failure
How do you run these scripts: by command line or by using some web URL?
Oleg Yershov
Re: Send e-mail notification after script success/failure
There are two ways to achieve this.
1-st way.
Put into PHP script such code
die(<exit_code>);
-or-
exit(<exit_code>);
I use for my test simple script:
i.e. my script generates the exit code 10.
You can catch and analyze this code in RoboTask (see screenshot) See full task below:
2-nd way
You can save the output result of the script into a file and analyze this text.
You can test this text on specific word or phrase (for example the word "Error")
I use such script for this example:
See the task below:
Save the text of the task ino a file and use menu Task->Import in order to import into RoboTask.
1-st way.
Put into PHP script such code
die(<exit_code>);
-or-
exit(<exit_code>);
I use for my test simple script:
Code: Select all
<?php
die(10);
?>
You can catch and analyze this code in RoboTask (see screenshot) See full task below:
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|317955339
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task841"
Hide=INTEGER|0
ID=INTEGER|436396385
LogOnAsUser=INTEGER|1
Name=STRING|"Run php and return code"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""ERR"" with value ""0"""
Params=FOLDER
[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"ERR"
varvalue=STRING|"0"
[Actions\Action2]
ActionID=STRING|"A_GENERAL_RUN_PROG"
Enabled=INTEGER|-1
Name=STRING|"Run ""php.exe ""D:\test\php\script1.php"" """
Params=FOLDER
[Actions\Action2\Params]
ifnonzero=STRING|"0"
params=STRING|"""D:\test\php\script1.php"" "
program=STRING|"C:\Program Files (x86)\PHP\v5.3\php.exe"
runas=STRING|"0"
variable=STRING|"ERR"
wait=STRING|"2"
[Actions\Action3]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action3\Params]
case=STRING|"0"
operator=STRING|"1"
type=STRING|"1"
value1=STRING|"{err}"
value2=STRING|"0"
[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Error: {err}"""
Params=FOLDER
[Actions\Action4\Params]
icon=STRING|"3"
msg0=STRING|"Error: {err}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action5]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
You can save the output result of the script into a file and analyze this text.
You can test this text on specific word or phrase (for example the word "Error")
I use such script for this example:
Code: Select all
<?php
die('Error: some problem');
?>
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|317955339
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task843"
Hide=INTEGER|0
ID=INTEGER|779559767
LogOnAsUser=INTEGER|1
Name=STRING|"Run php and return text"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
[Actions\Action1]
ActionID=STRING|"A_GENERAL_RUN_PROG"
Enabled=INTEGER|-1
Name=STRING|"Run ""cmd.exe /c """"C:\Program Files (x86)\PHP\v5.3\php.exe"" ""D:\test\php\script2.php"""" > {TempDir}\out.txt"""
Params=FOLDER
[Actions\Action1\Params]
ifnonzero=STRING|"0"
params=STRING|"/c{EOL}""""C:\Program Files (x86)\PHP\v5.3\php.exe""{EOL}""D:\test\php\script2.php"""" > {TempDir}\out.txt"
program=STRING|"cmd.exe"
runas=STRING|"0"
variable=STRING|"ERR"
wait=STRING|"2"
[Actions\Action2]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action2\Params]
case=STRING|"0"
operator=STRING|"6"
type=STRING|"0"
value1=STRING|"error"
value2=STRING|"{TextFile({TempDir}\out.txt)}"
[Actions\Action3]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Error: """
Params=FOLDER
[Actions\Action3\Params]
icon=STRING|"3"
msg0=STRING|"Error: "
msg1=STRING|"{TextFile({TempDir}\out.txt)}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action4]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
Oleg Yershov
Re: Send e-mail notification after script success/failure
Ok, last question. Why if I die/exit script like this
it shows me alert
Code: Select all
<?php
die(99);
?>
Code: Select all
Error: 1
not 99?
Re: Send e-mail notification after script success/failure
Maybe it depends on PHP version
I use PHP 5.3.
Try to use expression
exit(99);
My PHP processes die and exit expressions equally
I use PHP 5.3.
Try to use expression
exit(99);
My PHP processes die and exit expressions equally
Oleg Yershov
Re: Send e-mail notification after script success/failure
exit also return 1 as variable, not 99. That's weird...