How to manage /var/mail/root file
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.
![darshan krishnaiah](https://lh5.googleusercontent.com/-Bhl0T9kIGCk/AAAAAAAAAAI/AAAAAAAAACc/sgO86J3jpBQ/photo.jpg?sz=256)
darshan krishnaiah
Updated on September 18, 2022Comments
-
darshan krishnaiah almost 2 years
The size of
/var/mail/root
has been increasing as i am using lot ofcron
jobs and may cause memory shortage.Is it wise to delete that file? How to manage this problem?
-
GammaGames over 4 yearsIf anyone gets any permissions issues, you can add
su root mail
to tell logrotate which user and group to use with the config