HeroS_NL
Posts: 17
Joined: Mon Nov 04, 2013 10:07 pm

Cron keeps mailing

Sat Jan 11, 2014 5:30 pm

Hello,

I recently installed ssmtp to be able to send mails. Now at every cronjob command it seems to try to e-mail the output to the user where the cron is on.. Because this failed it sends an e-mail to itself (I'm using a gmail adress). The annoying part is that every 5 minutes there is a cron job, so I get a massive load of e-mails..

E-mail 'conversation' looks like this:

first e-mail its trying to send for some reason (??)
From: (this is the account I setted up)
to: root

Phone absent, starting motion
Motion already running
Done starting motion
This is the output of a bash file when I just run it on the foreground.

Directly after that I receive another e-mail straight back from myself:
From: Mail Delivery Subsystem <mailer-daemon@googlemail.com>
to:
Subject: Delivery Status Notification (Failure)

Delivery to the following recipient failed permanently:

pi@rasperry

Technical details of permanent failure:
DNS Error: Domain name not found

----- Original message -----

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=message-id:from:date:to:subject:content-type;
bh=srC7pUOsMTNerqudD4cKFYG5qN35zzoLiIwginEr1Xo=;
b=h9sMt8QmLUljiy6stD4xfhdYi9A9GflIiOpPtALpN3QmCyyIwMZN/d2CEpXioCn645
0FttsnlEPuudskWv3NTAy1bNmQJ/6zi8Bym+uibFUfhVx9dmC2e0DSoVUVOrqVN4OBqV
FXj9PUgRt04CSA6n8I+56YErsFateRcCHZvDyOCbQgLArrP3HySktiNcoqbUfg2WWQ1x
LaJfc1ipidzaqfSYHmwNdHnLBpyNsSEcI3FPJGGyaEpPz7Yo4b6ik/K9zWfBleJ2teTV
gSlghJQr7RU4m8GL8goL3mSiuoNvyTzijU2n4M9gS3al00tDpzP11HntLdxoex5EmJQT
iViw==
X-Received: by 10.14.212.69 with SMTP id x45mr17065007eeo.69.1389458420421;
Sat, 11 Jan 2014 08:40:20 -0800 (PST)
Return-Path: <>
Received: from Rasperry (dhcp-xxxxx-xxxxx..nl. [xxx.xxx.xxx.xxx]) <-my ip
by mx.google.com with ESMTPSA id o13sm24070668eex.19.2014.01.11.08.40.18
for <pi@rasperry>
(version=TLSv1 cipher=RC4-SHA bits=128/128);
Sat, 11 Jan 2014 08:40:19 -0800 (PST)
Message-ID:
Received: by Rasperry (sSMTP sendmail emulation); Sat, 11 Jan 2014 17:40:17 +0100
From: "root" <@gmail.com>
Date: Sat, 11 Jan 2014 17:40:17 +0100
To: root
Subject: Cron <root@Rasperry>
Content-Type: text/plain; charset=UTF-8
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>

How can I disable that it keeps sending information of the output of every cron job? I know I setted up the e-mail wrong (DNS Error), but I want that it stops sending e-mails from cron at all.
Last edited by HeroS_NL on Sun Oct 19, 2014 5:43 pm, edited 2 times in total.

User avatar
jojopi
Posts: 3268
Joined: Tue Oct 11, 2011 8:38 pm

Re: Cron keeps mailing

Sat Jan 11, 2014 9:37 pm

If the job produces any output at all, then cron will try to mail it. The best way to write jobs is so that they produce no output when they succeed, or encounter expected minor errors, but do print errors if they fail.

However, to adapt an existing job that is too noisy, just redirect stdout and if necessary stderr to a file, or to /dev/null:

Code: Select all

*/5 * * * * THESCRIPT >/dev/null 2>/dev/null
Every five minutes is getting to the point where it might be better to run the program from a continuous loop script. cron has significant overheads in terms of logging and such, even without email.

Since you are using an internet rather than local mail server you should add a MAILTO=user@domain line to the top of your crontab, with a valid routeable email address to avoid the bounces.

Alternatively, you can use MAILTO="" to completely disable email.

jnm21
Posts: 1
Joined: Wed Apr 29, 2015 3:47 am

Re: Cron keeps mailing

Wed Apr 29, 2015 3:52 am

Thank you so much jojopi - I had been round in circles trying to stop cron emailing pi@raspberrypi.

Return to “Troubleshooting”