Feature #374

cron should send more useful mail

Added by Joshua Clulow almost 7 years ago. Updated over 4 years ago.

Status:ResolvedStart date:2010-10-25
Priority:NormalDue date:
Assignee:Joshua Clulow% Done:

100%

Category:cmd - userland programs
Target version:-
Difficulty:Medium Tags:

Description

I think we should replace the ancient and unhelpful:

Subject: Output from "cron" command

with something more like what comes out of OpenBSD:

Subject: Cron: <leftwing@thor> /usr/local/bin/backups

Proposed diff:

diff -r ef8c14905c5a usr/src/cmd/cron/cron.c
--- a/usr/src/cmd/cron/cron.c   Fri Oct 22 16:59:15 2010 -0700
+++ b/usr/src/cmd/cron/cron.c   Mon Oct 25 10:34:29 2010 -0700
@@ -145,7 +145,6 @@
 #define        CLOCK_DRIFT     "clock time drifted backwards after event!\n" 
 #define        PIDERR          "unexpected pid returned %d (ignored)" 
 #define        CRONTABERR      "Subject: Your crontab file has an error in it\n\n" 
-#define        CRONOUT         "Subject: Output from \"cron\" command\n\n" 
 #define        MALLOCERR       "out of space, cannot create new string\n" 

 #define        DIDFORK didfork
@@ -2725,7 +2724,8 @@
                exit(127);
        (void) fprintf(mailpipe, "To: %s\n", p->name);
        if (pr->jobtype == CRONEVENT) {
-               (void) fprintf(mailpipe, CRONOUT);
+               (void) fprintf(mailpipe, "Subject: Cron <%s@%s>: %s\n\n",
+                   p->name, name.nodename, pr->jobname);
                (void) fprintf(mailpipe, "Your \"cron\" job on %s\n",
                    name.nodename);
                if (pr->jobname != NULL) {

History

#2 Updated by Joshua Clulow almost 7 years ago

new webrev: http://cr.illumos.org/view/bshjfk9z/

crontab now supports entries like this:

MAIL_SUBJECT=Custom Subject Line
* * * * * cat /etc/release

MAIL_SUBJECT applies only to the crontab entry that immediately follows it, after which it resets to the default substitution string.

#3 Updated by Matt Lewandowsky almost 7 years ago

I don't agree with changing the default cron subject so dramatically. It will almost surely cause almost every sysadmin's mail filters to break...

If it must be changed, I suggest the following format for better compatibility:

Subject: Output from "cron" command <user@host> /path/to/cmd

This way some/most filters will continue to work, causing less grumbling from those who have the most output from cron and are therefore most likely to object to the change, no matter how overall beneficial.

Alternatively, there is always the option of Yet Another Config File/Option. Perhaps /etc/cron.d/mailformat or something? That would allow the admin to choose the default subject style (old/new/custom), potentially pleasing everybody. Perhaps make the "old" style default in the absence of the file and allow distros to populate it with defaults/comments as they wish.

Yes, it's a bit of extra work, but it's a more flexible end result. Also, it seems to be more flexible than what any other cron that I know of is capable of doing. It would be nice to see some interesting innovations to old standby tools. :)

Just my opinion, of course. If others don't take offense to changing the default subject line, I have no other objections to the most recent webrev.

#4 Updated by Joshua Clulow almost 7 years ago

I agree on configurability of the new subject format as being a good idea.

Also, there's been significant change since the last update to this bug on the mailing lists -- most recent message in thread (which includes a link to the latest webrev) is here:

http://lists.illumos.org/pipermail/developer/2010-November/000965.html

#5 Updated by Matt Lewandowsky almost 7 years ago

I have reviewed the update, as well:

  • I have no comments on the auditing stuff. That's not something I can offer useful input upon.
  • The lint stuff makes it hard to read.
  • There was a style nit I found in at.c that I told you about on IRC.
  • Aside from the concerns in my last comment, I have nothing further to add to this bug, and the webrev looks OK to me.

#6 Updated by Joshua Clulow almost 7 years ago

I'll unpick the lint stuff and turn that into a separate bug and make the new subject behaviour a toggle.

#7 Updated by Joshua Clulow over 4 years ago

  • Difficulty set to Medium
  • % Done changed from 0 to 100
  • Status changed from New to Resolved
commit 42c141d3747f50c9bfb13e3cf5f32828312a7b79
Author: Joshua M. Clulow <josh@sysmgr.org>
Date:   Mon Jan 21 12:21:50 2013 -0800

    374 cron should send more useful mail
    Reviewed by: Richard Lowe <richlowe@richlowe.net>
    Approved by: Dan McDonald <danmcd@nexenta.com>

Also available in: Atom