Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to change the username for cron emails ?

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
DoubleHP
Posts: 72
Joined: 2016-10-09 08:55
Has thanked: 1 time

How to change the username for cron emails ?

#1 Post by DoubleHP »

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 ?

bigrigdriver
Posts: 145
Joined: 2014-09-01 17:04
Location: East Central Illinois, USA

Re: How to change the username for cron emails ?

#2 Post by bigrigdriver »

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 !!!

DoubleHP
Posts: 72
Joined: 2016-10-09 08:55
Has thanked: 1 time

Re: How to change the username for cron emails ?

#3 Post by DoubleHP »

My MUA can't do this. I want to fix the problem at the source.

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: How to change the username for cron emails ?

#4 Post by debiman »

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?

DoubleHP
Posts: 72
Joined: 2016-10-09 08:55
Has thanked: 1 time

Re: How to change the username for cron emails ?

#5 Post by DoubleHP »

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: 72
Joined: 2016-10-09 08:55
Has thanked: 1 time

Re: How to change the username for cron emails ?

#6 Post by DoubleHP »

Binary file /usr/sbin/cron matches

if I alter it with binary tools, will it still work, or are there checksums around ?

DoubleHP
Posts: 72
Joined: 2016-10-09 08:55
Has thanked: 1 time

Re: How to change the username for cron emails ?

#7 Post by DoubleHP »

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.

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

Re: How to change the username for cron emails ?

#8 Post by shep »


DoubleHP
Posts: 72
Joined: 2016-10-09 08:55
Has thanked: 1 time

Re: How to change the username for cron emails ?

#9 Post by DoubleHP »

shep nope, not better.

Post Reply