Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

root's daily/weekly/monthly mail UNIX
If you leave your OSX box up and running 24/7 and have been burning some midnight oil, you might have noticed some system activity in the early hours. If you look in /etc/crontab, you'll see that the root user runs some nightly, weekly and monthly security and maintenance tasks. Whenever cron produces output, it gets emailed to the job owner, so in this case root will be sent email nightly, weekly and monthly.

Unless you're in the habit of logging in as root and reading the email there it's more useful to have all of root's email redirected to your own mailbox. As with most (all?) unix systems, you can do this by creating a .forward file for the root user. Read the rest of this article if you'd like instructions on how to create this file.

In a terminal session, type the following commands (note that the "#" and following text are placed there as useful comments; you should not include these in the commands you issue). Replace username with your normal user's login name.
su
#respond with root's password
cd
#change to root's home dir
echo username > .forward
#creates a file called .forward and puts the word username in it
chmod 600 .forward
#Make the file read/write only by root
Now all of root's mail will be forwarded to username instead. The mail is kept in /var/mail/username, and you should be able to read it by typing mail in the terminal window.

Unfortunately there's a bug in the public beta of OSX's that means unix mailboxes (in /var/mail) can't be modified by users until the directory they live in is made world writeable, here's the fix:
su
chmod 777 /var/mail
chmod +t /var/mail
The '777' means unrestricted access to all, and the '+t' means that only the owner of a file in that directory can overwrite it. Mailboxes are created with permission so that only the owner can read and write them.
    •    
  • Currently 3.17 / 5
  You rated: 2 / 5 (6 votes cast)
 
[6,187 views]  

root's daily/weekly/monthly mail | 6 comments | Create New Account
Click here to return to the 'root's daily/weekly/monthly mail' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
I'd forgotten about that!
Authored by: robg on Feb 10, '01 10:36:21AM

Started a terminal, typed 'su' and 'mail' ... 21 messages! Needless to say, I created the .forward file!

Thanks for the tip!

-rob.



[ Reply to This | # ]
/dev/null
Authored by: Anonymous on May 31, '01 09:49:54AM

seems that in 10.0 release and above, apple thought that this might be not so practical for "regular" users... when i last checked (v 10.0.3) root's .forward had

>/dev/null

or in another words.. black hole.. or should we say "Trash" in our pre MacOS X terminology?...



[ Reply to This | # ]
how big does this get?
Authored by: ClarkGoble on Apr 04, '01 09:18:53PM

Weird question. Since most regular users will never log in as root, how big will this mail file get? It seems like unless they have something deleting old mail regularly that the file will get quite large.



[ Reply to This | # ]
not very big
Authored by: robh on Apr 05, '01 11:48:16AM

Most users won't have the machine switched on overnight when the cron jobs run, so I doubt it'll be a problem for the majority of users.

The nightly mail takes about 1k of diskspace. Add on the weekly and monthly checks and the mailbox shouldn't grow by more than 0.5Mb a year if left unread.



[ Reply to This | # ]
how big does this get?
Authored by: klktrk on Apr 19, '02 01:07:24PM

By default, the Mac OS X system is set up to forward all of root's mail to /dev/null, which is UNIX speak for "send it out into the void."

There is no mail buildup.



[ Reply to This | # ]
Mail doesn't work
Authored by: fbitterlich on Dec 05, '02 03:58:07PM

Any clue why my system isn't able to send mail? If I send mail with the -v option, I get the message...

bit... connection to localhost via relay...
bit... Deferred: Connection refused by localhost

What's wrong here? 10.1.5, and "bit" is my username.



[ Reply to This | # ]