Question

How to manage /var/mail/root file

The size of /var/mail/root has been increasing as i am using lot of cron jobs and may cause memory shortage. Is it wise to delete that file? How to manage this problem?

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 18, 2016
Accepted Answer

Hi!

I would recommend emptying the file instead of completely deleting it just to prevent any issues that might be caused by the file being missing.

cat /dev/null > /var/mail/root

You can disable cron emails completely by adding MAILTO="" to your cron file. Run crontab -e and add that line above your cron jobs. If you want to disable emails for just one cron job, you will need to redirect its output to /dev/null by adding > /dev/null 2>&1 at the end of the line. For example:

* * * * */5 /path/to/command arguments > /dev/null 2>&1

You can disable cron emails completely by adding MAILTO=“” to your cron file. Run crontab -e and add that line above your cron jobs. If you want to disable emails for just one cron job, you will need to redirect its output to /dev/null by adding > /dev/null 2>&1 at the end of the line. For example:iuh

2 ways to tackle this.

  1. send all root emails to /dev/null This is a sledgehammer approach that means you might miss some important error messages. But if you don’t care too much you can append
    > /dev/null to the end of any cron job you don’t want an output from. E.G. 0 * * * * python /etc/tidy-log-files.py > /dev/null

2 ) redirect root mail to a physical email address you own. This is the safer way then you can see the output and deal with it without filling your server.

go to /etc/aliases

add in a line : root: my-email@gmail.com So now every time root gets and email it’s redirected to the external email address instead.

As for the current load. either delete the file and recreate it as root. Or use the mail command to look through and delete emails manually

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.