Hi,
Currently, the crond (or cronie) has support for MAILTO variable to have the cron send the messages to a different email address than that of the user. I noticed that cron messages have weird subject form that of username, hostname and (lengthy) command line used. I took a look at the cronie source and it sounded fairly trivial for adding support for configurable subject strings to the code base.
So in the cronjobs, users can have MAIL_SUBJECT as the environment variable along with MAILTO environment variable that allows to modify the cron email's subject.
So, here is the patch I think works for me, but please let me know if there is anything else that needs to be checked in before having the patch committed.
thanks, Nikhil
--- a/src/do_command.c +++ b/src/do_command.c @@ -88,7 +88,7 @@ void do_command(entry * e, user * u) {
static int child_process(entry * e, char **jobenv) { int stdin_pipe[2], stdout_pipe[2]; - char *input_data, *usernm, *mailto, *mailfrom; + char *input_data, *usernm, *mailto, *mailfrom, *mail_subject; int children = 0; pid_t pid = getpid(); struct sigaction sa; @@ -125,6 +125,7 @@ static int child_process(entry * e, char **jobenv) { */ usernm = e->pwd->pw_name; mailto = env_get("MAILTO", jobenv); + mail_subject = env_get("MAIL_SUBJECT", jobenv); mailfrom = env_get("MAILFROM", e->envp);
/* create some pipes to talk to our future child @@ -437,8 +438,15 @@ static int child_process(entry * e, char **jobenv) {
fprintf(mail, "From: "(Cron Daemon)" <%s>\n", mailfrom); fprintf(mail, "To: %s\n", mailto); - fprintf(mail, "Subject: Cron <%s@%s> %s\n", - usernm, first_word(hostname, "."), e->cmd); + /* MAIL_SUBJECT is set but if it is empty? */ + if (mail_subject && *mail_subject) { + fprintf(mail, "Subject: %s\n", mail_subject); + } else { + fprintf(mail, "Subject: Cron <%s@%s> %s\n", + usernm, + first_word(hostname, "."), + e->cmd); + }
Hi,
I was wondering if this patch can be taken upstream so that I do not have to manage a local code base :-) Please let me know if there are any suggestions to take this forward.
thanks, Nikhil
On Thu, Jan 30, 2014 at 4:46 PM, Nikhil mnikhil@gmail.com wrote:
Hi,
Currently, the crond (or cronie) has support for MAILTO variable to have the cron send the messages to a different email address than that of the user. I noticed that cron messages have weird subject form that of username, hostname and (lengthy) command line used. I took a look at the cronie source and it sounded fairly trivial for adding support for configurable subject strings to the code base.
So in the cronjobs, users can have MAIL_SUBJECT as the environment variable along with MAILTO environment variable that allows to modify the cron email's subject.
So, here is the patch I think works for me, but please let me know if there is anything else that needs to be checked in before having the patch committed.
thanks, Nikhil
--- a/src/do_command.c +++ b/src/do_command.c @@ -88,7 +88,7 @@ void do_command(entry * e, user * u) {
static int child_process(entry * e, char **jobenv) { int stdin_pipe[2], stdout_pipe[2];
char *input_data, *usernm, *mailto, *mailfrom;
char *input_data, *usernm, *mailto, *mailfrom, *mail_subject; int children = 0; pid_t pid = getpid(); struct sigaction sa;
@@ -125,6 +125,7 @@ static int child_process(entry * e, char **jobenv) { */ usernm = e->pwd->pw_name; mailto = env_get("MAILTO", jobenv);
mail_subject = env_get("MAIL_SUBJECT", jobenv); mailfrom = env_get("MAILFROM", e->envp); /* create some pipes to talk to our future child
@@ -437,8 +438,15 @@ static int child_process(entry * e, char **jobenv) {
fprintf(mail, "From: \"(Cron Daemon)\"
<%s>\n", mailfrom); fprintf(mail, "To: %s\n", mailto);
fprintf(mail, "Subject: Cron <%s@%s>
%s\n",
usernm, first_word(hostname, "."),
e->cmd);
/* MAIL_SUBJECT is set but if it is empty?
*/
if (mail_subject && *mail_subject) {
fprintf(mail, "Subject: %s\n",
mail_subject);
} else {
fprintf(mail, "Subject: Cron <%s@%s>
%s\n",
usernm,
first_word(hostname, "."),
e->cmd);
}
On 02/13/2014 07:14 PM, Nikhil wrote:
Hi,
I was wondering if this patch can be taken upstream so that I do not have to manage a local code base :-) Please let me know if there are any suggestions to take this forward.
thanks, Nikhil
On Thu, Jan 30, 2014 at 4:46 PM, Nikhil <mnikhil@gmail.com mailto:mnikhil@gmail.com> wrote:
Hi, Currently, the crond (or cronie) has support for MAILTO variable to have the cron send the messages to a different email address than that of the user. I noticed that cron messages have weird subject form that of username, hostname and (lengthy) command line used. I took a look at the cronie source and it sounded fairly trivial for adding support for configurable subject strings to the code base. So in the cronjobs, users can have MAIL_SUBJECT as the environment variable along with MAILTO environment variable that allows to modify the cron email's subject. So, here is the patch I think works for me, but please let me know if there is anything else that needs to be checked in before having the patch committed. thanks, Nikhil --- a/src/do_command.c +++ b/src/do_command.c @@ -88,7 +88,7 @@ void do_command(entry * e, user * u) { static int child_process(entry * e, char **jobenv) { int stdin_pipe[2], stdout_pipe[2]; - char *input_data, *usernm, *mailto, *mailfrom; + char *input_data, *usernm, *mailto, *mailfrom, *mail_subject; int children = 0; pid_t pid = getpid(); struct sigaction sa; @@ -125,6 +125,7 @@ static int child_process(entry * e, char **jobenv) { */ usernm = e->pwd->pw_name; mailto = env_get("MAILTO", jobenv); + mail_subject = env_get("MAIL_SUBJECT", jobenv); mailfrom = env_get("MAILFROM", e->envp); /* create some pipes to talk to our future child @@ -437,8 +438,15 @@ static int child_process(entry * e, char **jobenv) { fprintf(mail, "From: \"(Cron Daemon)\" <%s>\n", mailfrom); fprintf(mail, "To: %s\n", mailto); - fprintf(mail, "Subject: Cron <%s@%s> %s\n", - usernm, first_word(hostname, "."), e->cmd); + /* MAIL_SUBJECT is set but if it is empty? */ + if (mail_subject && *mail_subject) { + fprintf(mail, "Subject: %s\n", mail_subject); + } else { + fprintf(mail, "Subject: Cron <%s@%s> %s\n", + usernm, + first_word(hostname, "."), + e->cmd); + }
Cronie-devel mailing list Cronie-devel@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/cronie-devel
Hi, thanks for patch. I wonder what can break, but I didn't find anything in RFE and it shouldn't break backward compatibility. Could you regenerate the patch to be applicable on [1] and add it as attachment?
[1]https://git.fedorahosted.org/cgit/cronie.git
Thanks, Marcela
cronie-devel@lists.stg.fedorahosted.org