Cron jobs not sending mail  [SOLVED]

Discussions about the usage of KeyHelp.
Post Reply
kurgans
Posts: 16
Joined: Mon 2. Nov 2020, 12:57

Cron jobs not sending mail

Post by kurgans »

Good afternoon everyone

Sorry for my English I only speak Spanish

I have observed in my panel that the emails with the outputs of a cron task are not sent by email

I look in the logs and I can't find a reason

I test the panel with a mail for general users and I see that the mail() function works correctly.

Some help to be able to see what happens with the emails of the scheduled jobs

Thank you
User avatar
Alexander
Keyweb AG
Posts: 3810
Joined: Wed 20. Jan 2016, 02:23

Re: Cron jobs not sending mail

Post by Alexander »

Hello,

do you send the emails within your script yourself or do you rely on the Cron daemon to send the emails, when there is any output of the script (btw. it does not use the mail() function)?

If later, please provide the way, how you setup the scheduled task notification settings and read the help text:
KeyHelp wrote:On Error
The notification contains the error output of the command (= standard error stream, STDERR). If the output is empty, no notification is sent.
KeyHelp wrote:Always
The notification contains the output of the command (= standard output stream, STDOUT). If the output is empty, no notification is sent
Make sure your script writes into the correct output stream to let the cron deamon catch the error and send the mail.
Mit freundlichen Grüßen / Best regards
Alexander Mahr

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
http://www.keyweb.de - http://www.keyhelp.de
**************************************************************
kurgans
Posts: 16
Joined: Mon 2. Nov 2020, 12:57

Re: Cron jobs not sending mail

Post by kurgans »

Good afternoon

Forgive my English .. if there is something badly expressed

If I understand what you are saying about sending cron without output.

and always send the errors to the mail without problem

On this occasion, to control a document number, the cron was told to send by mail everything that had output

I indicate the cron by ssh put in the panel

# Cron Documents
MAILTO="mymail@gmail.com"
20 9 * * * php /home/users/development/www/myweb/artisan tracking:email

This task generates an output... which is visible by the control panel when run manually

But it is never sent by mail .. it only sends an error

Thanks for everything

-----------------------------------
Estado: Finalizado

Tiempo de ejecución: 00:00:00
Código de estado de devolución: 0 (Éxito)
Salida:

Cantidad de documentos: 3
Documentos .. {33.33%} | 1 de 3
Documentos .. {66.67%} | 2 de 3
Documentos .. {100%} | 3 de 3
User avatar
Alexander
Keyweb AG
Posts: 3810
Joined: Wed 20. Jan 2016, 02:23

Re: Cron jobs not sending mail

Post by Alexander »

To help you, you can use https://www.deepl.com/translator for translating - it produces high quality translations ;).

Can you provide a screenshot of the cronjobs / scheduled tasks within the KeyHelp user interface - just to let me check if everything is setup correctly.
(Attention - you may want to anonymize your email address)

# Cron Documents
MAILTO="mymail@gmail.com"
20 9 * * * php /home/users/development/www/myweb/artisan tracking:email
Is this the output of this the following command? If not, please provide the output of this command. Replace <USERNAME> with the appropriate username.

Code: Select all

crontab -u <USERNAME> -e
Mit freundlichen Grüßen / Best regards
Alexander Mahr

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
http://www.keyweb.de - http://www.keyhelp.de
**************************************************************
kurgans
Posts: 16
Joined: Mon 2. Nov 2020, 12:57

Re: Cron jobs not sending mail

Post by kurgans »

Thanks for the recommendation for the translator

Correct, the output I have set is crontab -u desarrollo -e,

I attach the image of keyhelp

Thanks
Attachments
cron.jpg
User avatar
Alexander
Keyweb AG
Posts: 3810
Joined: Wed 20. Jan 2016, 02:23

Re: Cron jobs not sending mail

Post by Alexander »

It seems, that the output of the called script does not write to the STDOUT stream (standard output), and therefor may not be captured by the Cron-Daemon. What software do you use?


Some ideas to further investigate:

- Run this command (artisian seguimiento:email) on the CLI itself and see, how it behaves, make sure there are no interactive messages by the script etc.

- Check the code of the script and how it outputs the data

- Create a wrapper script, where you catch the output of your script and call this wrapper script as cronjob, instead of "artisian seguimiento:email"

- Redirect the STDERR to STDOUT by adding "2>&1" to the end of the command e.g. "... artisian seguimiento:email 2>&1"

- Check if the Cron-Daemon would send an emails when just calling a simple test script e.g. " <?php echo 'Test'; "
Mit freundlichen Grüßen / Best regards
Alexander Mahr

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
http://www.keyweb.de - http://www.keyhelp.de
**************************************************************
kurgans
Posts: 16
Joined: Mon 2. Nov 2020, 12:57

Re: Cron jobs not sending mail  [SOLVED]

Post by kurgans »

Good afternoon

Sorry for the delay ... work has been hard during this time and I could not look at your instructions.

- after following your instructions it was not responding
- I tried on another server and it worked without problems ...

I restarted the server and create the processes again and everything has worked correctly the error outputs, as the correct outputs.


Thank you very much for everything
Post Reply