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?

1 Answer

You should handle these kind of issues with logrotate, it is designed for these tasks specifically.

For example, to enable logrotate to rotate the file /var/mail/root if the size of the file becomes 10 MB, you can add a logrotate configuration file e.g. /etc/logrotate.d/mailroot with the content:

/var/mail/root { # Rotate if the size is >=10MB: size 10M # Keep 5 rotated logs: rotate 5 # Do not rotate if empty: notifempty # Compresses rotated logs, default: compress
}

You can define for the whole directory too using wildcard, *, so that it will be applicable to all files under it:

/var/mail/* {
....
}

As logrotate is run daily by cron (anacron), you do not need to add any cron entry if the configuration is put in /etc/logroate.conf or /etc/logroate.d/*. You can also define your own crontab entry if the configuration file resides elsewhere, you might also need a state file that will contain the current file rotation tatus.

Most importantly, check man logroate and man 5 logroate.conf to get more idea and options.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like