M
M
Mortech2020-10-26 17:22:27
PHP
Mortech, 2020-10-26 17:22:27

Is it necessary that information about an unsuccessful launch through the crontab of any task be sent to a specific email?

There is a php script /home/clients/test_ftp0/domains/ example.com/html/sendEmail.php . It is set to 00 9,15 * * 1,3,5 wget example.com/sendEmail.php . How can I make sure that all error information from all domains on this account is sent to a specific email address?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Yuriev, 2020-10-26
@Mortech

at the beginning of the crontab ( sudo -u %username% crontab -e) add a line
MAILTO=
with the desired soap.
And set the STDOUT output of the command to /dev/null so that successful executions do not arrive to you.

[email protected]
0 */2 * * * /bin/backup.sh > /dev/null

PS: do not run via wget, but rewrite it to php-cli and move it outside the document_root of the site so that it cannot be reached from outside.

A
Anton Shamanov, 2020-10-26
@SilenceOfWinter

we set set_error_handler throwing ErrorException (see manual) and wrap the code in try / catch, in the catch block we log the error using syslog, to open the log we use openlog with the argument facility = LOG_MAIL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question