How to manage /var/mail/root file

July 18, 2016 18.6k views
Linux Basics Storage

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?

1 comment
2 Answers
kamaln7 MOD 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
  • Hey,

    I have the same problem: my var/vmail/user/root/new folder has over 90Gb.

    Via SSH when i use "-ls" to see all the files in the folder it seems there are many (over 1000 files). Please tell me what is the right way to clear all that space.

    I tried the cat /dev/null > /var/vmail/user/root/new but i receive an error:
    "An error occurred while redirecting file '/var/vmail/user/root/new/'
    open: Is a directory"

    This is very urgent.

    Thank you,
    Victor

    • You should be able to delete everything in that directory without breaking anything, but it depends on what mail software your running. To delete all files, run:

      sudo rm -r /var/vmail/user/root/new/*
      

      Make sure there are no spaces in the path in red. The cat command in the original post clears a file, but since this is a text file, you need to delete all the files inside of it. Hope that helps!

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

Have another answer? Share your knowledge.