0

I have cron set to run a task for user pi (on my Raspberry Pi running Raspbian Stretch) every 15 minutes.

6,21,36,51 * * * * /usr/bin/mosquitto_sub -h Pi3Plus.local -v -C 1 -t weather >> weather.log

I also have ssmtp setup to send email via gmail.

Every so often the cron task fails to connect to the server, and generates an error message.

The problem is that it then attempts to send a message to user pi, which ssmtp changes to pi@gmail and sends to gmail, where it fails.

I have read the man for ssmtp, ssmtp.conf, cron, crontab but cannot find anything to stop these messages.

I could write a script to trap error messages in the cron task to prevent it generating an error.

1

From the crontab manual:

In addition to LOGNAME, HOME, and SHELL, cron(8) will look at MAILTO if it has any reason to send mail as a result of running commands in "this" crontab. If MAILTO is defined (and non-empty), mail is sent to the user so named. If MAILTO is defined but empty (MAILTO=""), no mail will be sent. Otherwise mail is sent to the owner of the crontab.

Simply add the variable to the top of the crontab file, as shown in this example (taken from the same man page, slightly edited for clarity):

# mail any output to 'paul', no matter whose crontab this is
MAILTO=paul
# run five minutes after midnight, every day
5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.