1846590 Members
2207 Online
110256 Solutions
New Discussion

script

 
SOLVED
Go to solution
Sanjiv Sharma_1
Honored Contributor

script

Hi,

Some of the files in the /var/mail folder are growing very fast.

I am looking for a script which read/list all the files under /var/mail and trim the files which are more than 2 MB in size.

Thank you,
Everything is possible
7 REPLIES 7
Mel Burslan
Honored Contributor
Solution

Re: script

As you are aware, these files are the mail containers for the users on this system.

due to this fact, instead of trimming the files, I would suggest one of the two things :

1) if any particular user does not read his/her emails, it means that they do not need it and it can and should be turned off.

2) if they really need it, but can not find time to read them, you can place a .forward file under these users' home directory and put their company-wide email address into this file and they will receive the mail in their outlook mailbox or what have you and they need to handle the growing mailbox pressure, not you.

At the end it is the users' email not yours to trim when the filesystem blows up.
________________________________
UNIX because I majored in cryptology...
Mel Burslan
Honored Contributor

Re: script

but if you insist on trimming the files, here you go

cd /var/mail
for file in `find . -size +2000000c`
do

linecount=`cat $file | wc -l`
let trimamount=$linecount/10 # trimming 10% here, change as you wish
sed -e 1,${trimamount}d $file > /tmp/temp_mail_file
mv /tmp/temp_mail_file $file

done


as these files grow at the bottom, you want to trim them from the top.

hope this helps
________________________________
UNIX because I majored in cryptology...
KapilRaj
Honored Contributor

Re: script

somebody in the forum suggested me to go for a seperate filesystem mounted on /var/mail ...

Kaps
Nothing is impossible
Amit Dixit_2
Regular Advisor

Re: script

Hi,
If possible go fo the solution which kapil
proposed.

You cannot trust user for which mail they
will come to you and ask you to retrieve
so better add a disk and add it to
the /var/mail volume.

Thanks,
Amit
R. Allan Hicks
Trusted Contributor

Re: script

I don't know, but I really like mel's solutions.

You can't coddle users, if you do they will walk all over you and your system.

We have a similar problem with cron sending mail to root. Since no one usually logs on to root as normal practice, his mail file can really grow with mostly non-useful information.

Remember that data will expand to fill all of your available diskspace. :-)

If you thought being a system admin would make you popular, you'd best think again.
"Only he who attempts the absurd is capable of achieving the impossible
Hein van den Heuvel
Honored Contributor

Re: script


>> You can't coddle users, if you do they will walk all over you and your system.

Interesting point of view. Where I come from the system is there for the users. They own it. The system administrator is the facilitator, not a dictator / owner.

>> If you thought being a system admin would make you popular, you'd best think again.

I suppose that would be the natural consequence of treating the users as 'the enemy' that are reluctantly tolerated on 'your system'.

fwiw,
Hein.

Mel Burslan
Honored Contributor

Re: script

Well, my position was not to be the dictator of the system. Yes, the reason of being in place for any system is to be used by the "users". But on the other hand, in all my workplaces so far, and they are a handful, if you trust the user to take action against something adverse happening to the system that you are the sysadmin of, at best it is wishful thinking. This is why the quota concept was in place. Data, actually expands to fill all available disk space. It is a fact.

Sysadmin is not and should not be a dictator, but if a user is misbehaving, it is the sysadmin's role to be police/judge to penalize them. It would be nice if we all lived in a world where every user was a responsible person and clean up after themselves but this is what the fantasy role playing games are for :) Isn't it ?

Cheers.
________________________________
UNIX because I majored in cryptology...