1848300 Members
5228 Online
104024 Solutions
New Discussion

file limit

 
SOLVED
Go to solution
hangyu
Regular Advisor

file limit

In my server , there are some files under the directory /tmp , these files will growth very fast , I want to limit the size to grow to too large -- if the size is larger than a certain size ( eg. over 10M ) , then send the alert mail to me , could suggest what can I do ? thx
9 REPLIES 9
D Block 2
Respected Contributor
Solution

Re: file limit

you might just run something like this from the cron but to start with, write a small program to get started:

--
du -sk /tmp/* | sort -rn | head |mailx -s "top list" myeamil@address.com

--

the next phase you can use more tools like awk, etc.. to set a threshold and then only email yourself those files that are above a certain size length in Kb.

I'm sure the guys here will supply you with some tools..

good luck!

Golf is a Good Walk Spoiled, Mark Twain.
hangyu
Regular Advisor

Re: file limit

thx reply ,

but if I only want to gzip the files that over 10M size , what can I do ? thx
saju_2
Respected Contributor

Re: file limit

Hi

I am new to shell prg but try the one below


for i in `ls -lrt|egrep 'file1|file2'|awk '{print $5,$9}'|tr -s " "|sed s/" "/"#"/g`
do
if [ `echo $i|cut -f1 -d "#"` -gt 100000000000 ]
then
j=`echo $i|cut -f2 -d "#"`
echo "$j is greater than 10GB"
echo "Compressing the fiel $j
gzip $j
fi
done

replace file1 and file2 with the names of your files
Put the script in cron and redirect the output of this script to mailx and receive the mail


Verify the number of zeros in if loop also. bytes to GB conversion!!!!!

Regards
CS
saju_2
Respected Contributor

Re: file limit

hi

sorry i made it to 10Gb reduce 3 zeros in the if loop to make it to 10MB

regrdas

CS
D Block 2
Respected Contributor

Re: file limit

never compress any file that is being accessed or written to.. I mean, it might be open'ed by a process..

if the file is not being used, then you can do what you want to (gzip, whatever).

get yourself a really good tool called: LSOF

and figure if any process is using these big files in /tmp. If not, then do a gzip and move them out of /tmp into say: /usr/tmp or something else.

you can also use this simple option to ls:

ls -u /tmp/bigfile

if the file ACCESS time is old, then you might gzip.

I would hate to see you break something by trying to rename the file that is being written to or read from.. pls use caution.

Golf is a Good Walk Spoiled, Mark Twain.
hangyu
Regular Advisor

Re: file limit

thx replies,

I tried saju's script , but it seems too complicate for me , could suggest more simpler script ? thx
Joseph Loo
Honored Contributor

Re: file limit

hi,

i think u should look at the points u have assigned. 0 out of 30 (and counting) is not good.

http://forums2.itrc.hp.com/service/forums/pageList.do?userId=CA1293896&listType=unassigned&forumId=1

show your appreciation to those who have assisted u in finding your answers.

regards.



what you do not see does not mean you should not believe
D Block 2
Respected Contributor

Re: file limit

The script from SAJU looks good, why not give this person some Points ?



Golf is a Good Walk Spoiled, Mark Twain.
hangyu
Regular Advisor

Re: file limit

thx reply ,

I tried saju 's method but it seems don't have any output , and it is quite complicate for me so I don't know how to make it work , is there other simpler method can do that ? thx