Re: Failed cron jobs are silent

2015-01-03 Thread Edgar Pettijohn
It has for me.  I misspelled something in a script and cron sent me an 
email complaining about it.



On 01/03/15 09:50, Craig Skinner 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?

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 + (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
# http://en.wikipedia.org/wiki/111_(emergency_telephone_number)

# Mail:
* * * * * 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 -




Re: Failed cron jobs are silent

2015-01-03 Thread Bryan Horstmann-Allen
+--
| On 2015-01-03 14:02:15, Matthew Weigel wrote:
| 
 No, the behavior he described is accurate: cron(8) sends email if a job
 produced output, irrespective of its exit status.

 Google is littered with people trying to figure out how to get cron(8)
 to send email based on exit code... so it's certainly a common problem.
 Maybe some Unix decided to send email based on exit status, but
 OpenBSD's does not.

I have been wrapping cron jobs in App::Cronjob for ~5 years on Linux,
Solaris/illumos, and OpenBSD:

  http://search.cpan.org/~rjbs/App-Cronjob-1.24/lib/App/Cronjob.pm
  http://search.cpan.org/~rjbs/App-Cronjob-1.24/bin/cronjob
  http://advent.rjbs.manxome.org/2009/2009-12-07.html
  https://github.com/rjbs/App-Cronjob

Works quite well. Has other useful features in addition to emitting or
supressing noise on exit code.

Cheers.
-- 
bdha



Re: Failed cron jobs are silent

2015-01-03 Thread Jan Stary
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 + (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 -  1.33
+++ crontab.5   3 Jan 2015 20:12:08 -
@@ -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



Re: Failed cron jobs are silent

2015-01-03 Thread Fred

On 01/03/15 15:50, Craig Skinner 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?

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 + (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
# http://en.wikipedia.org/wiki/111_(emergency_telephone_number)

# Mail:
* * * * * 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 -



set the MAILTO variable in crontab.

hth

Fred
man 5 crontab not man 1 crontab
:~)



Failed cron jobs are silent

2015-01-03 Thread Craig Skinner
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?

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 + (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
# http://en.wikipedia.org/wiki/111_(emergency_telephone_number)

# Mail:
* * * * * 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 -



Re: Failed cron jobs are silent

2015-01-03 Thread Matthew Weigel

On 1/3/15 1:05 PM, Fred wrote:


man 5 crontab not man 1 crontab
:~)


No, the behavior he described is accurate: cron(8) sends email if a job
produced output, irrespective of its exit status.

Google is littered with people trying to figure out how to get cron(8)
to send email based on exit code... so it's certainly a common problem.
Maybe some Unix decided to send email based on exit status, but
OpenBSD's does not.
--
 Matthew Weigel
 hacker
 unique  idempot . ent