'Cannot stop cron from sending mail

I cannot stop cron from sending mails when setting this cron job:

*/1 * * * * python /scripts/releases/10_lftp.py | ts %F-%H:%M:%.S >> log.txt >> /scripts/releases/log.txt > /dev/null 2>&1

I've tried multiple versions of the above command, like:

*/1 * * * * python /scripts/releases/10_lftp.py | ts %F-%H:%M:%.S >> log.txt >> /scripts/releases/log.txt > 2>&1

*/1 * * * * python /scripts/releases/10_lftp.py > /dev/null 2>&1 | ts %F-%H:%M:%.S >> log.txt >> /scripts/releases/log.txt > /dev/null 2>&1

*/1 * * * * python /scripts/releases/10_lftp.py | ts %F-%H:%M:%.S > /dev/null 2>&1 >> log.txt >> /scripts/releases/log.txt > /dev/null 2>&1

But the above cron job keeps on sending mail (every minute), driving me nuts.

Note that I have other similar jobs like:

*/1 * * * * python /scripts/releases2/10_lftp.py | ts %F-%H:%M:%.S >> /scripts/releases2/log.txt 2>&1

which do not cause this problem (i.e. they do NOT send mails, as required).

What is wrong???

Can you please provide a solution or a workaround?

Thanks in advance, Nick



Solution 1:[1]

Cron sends mail, where this is an error.

So your task has an error on each invocation.

The error is reported in the email.

Suggesting to package your script into a single command script.

For example:

 python /scripts/releases/10_lftp.py | ts %F-%H:%M:%.S >> log.txt >> /scripts/releases/log.txt > /dev/null 2>&1

task_1.sh

 #!/bin/bash
 source /home/user/.bash_profile
 python /scripts/releases/10_lftp.py | ts %F-%H:%M:%.S >> log.txt >> /scripts/releases/log.txt > /dev/null 2>&1

crotab -l

 */1 * * * * /home/user/task_1.sh

It will be easier to debug and monitory your task_1.sh .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dudi Boy