# cron daemon mail



## nORKy (May 23, 2011)

Hi,

I have 2 FreeBSD 8.2 Servers. Both have a script started by crontab and the result is mailed to me. Why is the sender different?


```
1/
sender : Charlie &
Object : Cron <root@mysql1> /root/mbin/portupdater.sh
```


```
2/
Sender : Cron daemon
Object : Cron <root@smtp21> /root/mbin/portupdater.sh
```

Why one is "Root" and the other one is "Cron"?


----------



## pbd (May 23, 2011)

Standard (and error) output from command run by cron is by default sent as Cron Daemon. If you run the command from cron as root and this command *itself* sends an email, it will be from Charlie Root.

But assuming that your crontab entries and scripts portupdater.sh are the same on both servers, this is not the case. Is it?

What smtpd do you use on these servers?


----------



## SirDice (May 23, 2011)

Also compare the GECOS fields in /etc/passwd on both servers.


----------



## nORKy (May 24, 2011)

On both servers, my script is identical and is registered in root's crontab (with *crontab -e*) 

```
0 1 * * * /root/mbin/portupdater.sh
```

There is only this line.

/etc/passwd for root are identical in both servers.

smtp21 sends mail himself, because, it's an smtpd relay (postfix).
mysql1 sends mail to smtp21 (with ssmtp).

It's very "strange". My smtpd relay is a big postfix farm servers. I have mail from smtp11/12/13 and smtp21/22/23. Only smtp21 sends mail from "Cron daemon". Others send with "Charlie Root".


----------



## k-nike (May 11, 2012)

*additional question*

Hi, all!



> Standard (and error) output from command run by cron is by default sent as Cron Daemon.



How can *I* change it? I need to change the name of the sender.


----------



## pbd (May 11, 2012)

k-nike said:
			
		

> How can *I* change it? I need to change the name of the sender.



One way is change line


```
fprintf(mail, "From: %s (Cron Daemon)\n", usernm);
```

in /usr/src/usr.sbin/cron/cron/do_command.c and then recompile and reinstall cron.


----------



## SirDice (May 11, 2012)

Simply make sure the script doesn't output anything and uses its own mailx(1) command to send an email.


----------



## k-nike (May 11, 2012)

pbd said:
			
		

> One way is change line
> 
> 
> ```
> ...



Why then periodic scripts are sent on user behalf?


----------



## k-nike (May 14, 2012)

OpenSMTPD appeared in ports today. I have install*ed* it. The Username field in the email changed from "Cron Daemon" to "root".

When I installed ssmtp, the Username field in the email changed from "Cron Daemon" to GECOS field's "root".

Is it a b*u*g or a feature?


----------

