mail from: field question

Jim Bow jimbow at darq.net
Thu Jan 10 05:22:54 PST 2008


Mike Bristow wrote:
> On Thu, Jan 10, 2008 at 10:46:30AM +0000, Jim Bow wrote:
>> If I run the script (or just send a mail) on the command line using sudo, 
>> then it's sent as me and not root. Same happens if I su to root first.
> 
> use 'su -'.  It means you get a login shell (which sets up the enviroment
> in the same way that login does).

That makes perfect sense, but doesn't seem to work. Here's the output of 
my terminal session:

host% whoami
jim
host% sudo su - (tried doing "su -" also, with same results)
Password:
host# whoami
root
host# env
USER=root
HOME=/root
SHELL=/bin/csh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/root/bin
MAIL=/var/mail/root
BLOCKSIZE=K
FTP_PASSIVE_MODE=YES
TERM=screen
HOSTTYPE=FreeBSD
VENDOR=intel
OSTYPE=FreeBSD
MACHTYPE=i386
SHLVL=1
PWD=/root
LOGNAME=root
GROUP=wheel
HOST=host.example.com
EDITOR=vi
PAGER=more
host# cat /etc/motd  | mail -s "hello" test at example.com

This results in the mail from: header of jim at host.example.com. I've 
tried this on two different hosts with the same result.

The actual thing Im trying to do is to email something from a script 
that runs as root from devd, but I run into the same problem of the 
email arriving from somebody other than root, hence trying this manually 
on the command line.

There is definitely something that I am overlooking, but what is it? I'm 
extremely curious to work-out why I'm seeing such behavior as its 
defeating all my expectations so far.

Thanks for reading.


JimBow





More information about the freebsd-questions mailing list