On Jan 03 15:50:36, skin...@britvault.co.uk wrote: > Back in the memory of somewhere??? I worked, > failed cronjobs would mail their return code if not zero. > Something like: "Cron Job false exited with return code 1" > I cannae mind if it was Solaris or Linux, or whatever they were using... > Can OpenBSD's cron do that too?
Any output produced by a command is sent to the user specified in the MAILTO environment variable as set in the crontab(5) file or, if no MAILTO variable is set (or if this is an at(1) or batch(1) job), to the job's owner. If a command produces no output or if the MAILTO environment variable is set to the empty string, no mail will be sent. The exception to this is at(1) or batch(1) jobs submitted with the -m flag. In this case, mail will be sent even if the job produces no output. > Here's some silent & noisey sample shite jobs: > > ----- Forwarded message from Cron Daemon <r...@britvault.co.uk> ----- > > Date: Sat, 3 Jan 2015 15:30:02 +0000 (GMT) > From: Cron Daemon <r...@britvault.co.uk> > To: skin...@britvault.co.uk > Subject: Cron <luser@sir-puffy> crontab -l > > # Silent: > * * * * * true > * * * * * false > * * * * * exit > * * * * * exit 111 None of these produce any output, so no mail will be sent. > # Mail: Yes, because these produce output. > * * * * * false || print -u2 "exited with return code $?" > * * * * * false || print -u2 > 'http://en.wikipedia.org/wiki/One_Tree_Hill_(song)' > * * * * * crontab -l > * * * * * logname; umask; pwd; printenv | sort > > > ----- End forwarded message ----- On Jan 03 19:05:11, open...@crowsons.com wrote: > set the MAILTO variable in crontab. > man 5 crontab not man 1 crontab MAILTO 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. This is useful for pseudo-users that lack an alias that would otherwise redirect the mail to a real person. There seems to be a slight discrepancy between what cron.1 says and what crontab.5 says. I just put * * * * * true * * * * * false * * * * * echo -n * * * * * echo into my crontab (current/amd64). Echo sends an email, because it has an output (even if just the newline). The mail goes either to me, or whatever I set MAILTO to be. None of the others send any mail, regardless of MAILTO, because there is no output from the command. So it seems crontab.5 is slightly inacurate. Jan Index: crontab.5 =================================================================== RCS file: /cvs/src/usr.sbin/cron/crontab.5,v retrieving revision 1.33 diff -u -p -r1.33 crontab.5 --- crontab.5 30 Jan 2014 20:02:42 -0000 1.33 +++ crontab.5 3 Jan 2015 20:12:08 -0000 @@ -255,14 +255,16 @@ May not be overridden by settings in the If .Ev MAILTO is defined and non-empty, -mail is sent to the user so named. +mail is sent to the user so named +if the command produces any output. If .Ev MAILTO is defined but empty .Pq Ev MAILTO = Qq , no mail will be sent. Otherwise mail is sent to the owner of the -.Nm . +.Nm +if the command produces any output. This is useful for pseudo-users that lack an alias that would otherwise redirect the mail to a real person. .It Ev SHELL