How to change the username for cron emails ?

Kernels & Hardware, configuring network, installing services

How to change the username for cron emails ?

Postby DoubleHP » 2018-03-10 14:09

All my machines use a uniq hostname. So, each machin send cron emails with a from address like root@server1.com, root@server2.org ... but that email adress is suffixed with a user name; so when messages are received by MUA, the FROM field looks like:
From: root@server1.org (Cron Daemon)
or
From: root@server2.org (Cron Daemon)

but because my MUA is stupid, it only shows the username, not the full email address, so that all emails are shown to come from "Cron Daemon".

How can I alter the cron user name so that the username in parenthesis differs from host to host ?

Debian Stretch
exim

For messages sent from CLI by root, the fix was easy: in /etc/passwd, change
root:x:0:0:root:/root:/bin/bash
into
root:x:0:0:root DaServer01:/root:/bin/bash

But
grep -nr "Cron Daemon" /etc/
gave no result, so, it may be hardcoded in /usr ?
DoubleHP
 
Posts: 25
Joined: 2016-10-09 08:55

Re: How to change the username for cron emails ?

Postby bigrigdriver » 2018-03-10 18:54

There might be an easier solution, if your MUA allows you to set up filters to sort incoming mail into folders in the inbox.
1) set up folders for server1, server2, etc.
2) set up filters to sort FROM: root@server1.com to folder server1, FROM: root@server2.org into server2 folder, and so on.
With mail properly sorted, you know which host sent the mail by the folder the mail is in.
Registered GNU/Linux user #170078

Go ask google before you ask on these boards.

It it isn't broken, Tweak It !!!
bigrigdriver
 
Posts: 143
Joined: 2014-09-01 17:04
Location: East Central Illinois, USA

Re: How to change the username for cron emails ?

Postby DoubleHP » 2018-03-10 20:15

My MUA can't do this. I want to fix the problem at the source.
DoubleHP
 
Posts: 25
Joined: 2016-10-09 08:55

Re: How to change the username for cron emails ?

Postby debiman » 2018-03-11 07:19

reading
Code: Select all
man cron
you can search
Code: Select all
/mail
i can see at least 2 approaches to make this more distinct; have you checked them all out?
User avatar
debiman
 
Posts: 2396
Joined: 2013-03-12 07:18

Re: How to change the username for cron emails ?

Postby DoubleHP » 2018-03-11 08:16

I don't care about MAILTO; Debian does not support MAILFROM (some other distros do).

I was wondering if there is an easy way to change this at exim level ? (needs rewriting of the FROM field; a simple grep can do it, but not in the traditionnal way mta usually do it).

Otherwise, I have started grep -nr "Cron Daemon" /, but it will take the whole day.
DoubleHP
 
Posts: 25
Joined: 2016-10-09 08:55

Re: How to change the username for cron emails ?

Postby DoubleHP » 2018-03-11 08:19

Binary file /usr/sbin/cron matches

if I alter it with binary tools, will it still work, or are there checksums around ?
DoubleHP
 
Posts: 25
Joined: 2016-10-09 08:55

Re: How to change the username for cron emails ?

Postby DoubleHP » 2018-03-11 08:56

First shoot:

Code: Select all
#!/bin/bash
/etc/init.d/cron stop
grep -nra "Cron Daemon" /usr/sbin/cron
#66:[%d] %s/usr/sbin/sendmailinfoCONTENT_TYPECONTENT_TRANSFER_ENCODINGFrom: root (Cron Daemon)
grep -nra "From:" /usr/sbin/cron
cp -a /usr/sbin/cron /usr/sbin/cron.backup.$(/bin/date +%Y-%m-%d_%H-%M-%S).before
hn="$(hostname -f)................"
hn="${hn:0:11}"
echo "'${hn}'"
sed -i /usr/sbin/cron -e "s/(Cron Daemon)/(${hn})/g"
cp -a /usr/sbin/cron /usr/sbin/cron.backup.$(/bin/date +%Y-%m-%d_%H-%M-%S).after
grep -nra "From:" /usr/sbin/cron
/etc/init.d/cron start
stat /usr/sbin/cron*


Must be very carefull to check that the file size have not changed.
DoubleHP
 
Posts: 25
Joined: 2016-10-09 08:55

Re: How to change the username for cron emails ?

Postby shep » 2018-03-11 12:56

shep
 
Posts: 196
Joined: 2011-03-15 15:22

Re: How to change the username for cron emails ?

Postby DoubleHP » 2018-03-12 19:17

shep nope, not better.
DoubleHP
 
Posts: 25
Joined: 2016-10-09 08:55


Return to System configuration

Who is online

Users browsing this forum: bentHnau and 6 guests

fashionable