1825768 Members
2029 Online
109687 Solutions
New Discussion

lmit file size

 
SOLVED
Go to solution
peterchu
Super Advisor

lmit file size

I know there are some logs ( system or application log ) in the system , but I have some experience that sometimes these logs will growth to a unlimited size until the system is full ( maybe caused by system error ) , so that the system will be shutdown suddenly , is it possible to limit the log size ? or take some action such as gzip the file or inform system administrator when the file size over a certain of limit ? could provide suggestion ? thx.
8 REPLIES 8
Steven E. Protter
Exalted Contributor

Re: lmit file size

sam has a log trimming feature in it. You might want to do this once a week.

Or write a script that trims log files periodically.

> /var/adm/syslog/syslog.log

That trims the size to zero and saves a lot of space.

I have cron do this once a week with all big ugly, growing logs, if its important, I copy it off to tape before I do that.

If you were to try and limit the log by directing it to a small filesystem, you might find your system stops suddenly.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
David DeWitt_2
Frequent Advisor

Re: lmit file size

Here's a script I wrote to "archive" a file. It will keep '#' number of zip iterations. This allows you to retain say 40 iterations of data, but have 39 iterations worth compressed. In a moment I will post the "nightly" script I use to "archive" my files.

-dave
David DeWitt_2
Frequent Advisor

Re: lmit file size

Here's the nightly script.

-dave
David DeWitt_2
Frequent Advisor

Re: lmit file size

Oops. Be aware that the "nightly" script I posted calls for a "sec" script multiple times. The "sec" script is not needed for the log file archive. Just delete or comment out the lines that call for "sec". You should probably read through the scripts anyway and modify them for your environment.

-dave
David DeWitt_2
Frequent Advisor
Solution

Re: lmit file size

OTHER SUGGESTIONS...

You could monitor the size of log files and then execute an e-mail to the admin. Unfortunately, some log files can be missed during the setup. This is especially possible when new applications are loaded.

I suggest monitoring the filesystem space. Here is an excerpt from the "sec" script.

CHK_BDF () {
echo "CHK_BDF: Begin section code." >> $log_cur
bdf | grep -E "9.%|10.%" >> $log_cur
echo "CHK_BDF: End section code." >> $log_cur
}

This function lets me know when a filesystem reaches 90% or higher usage.

You could also use 'find' to search for any file over a certain size. That could get a little hairy depending on your environment.

find / -type f -size +# -exec ls -lad {} \;

where # is the size

If needed you can restrict the search to a directory or filesystem. See 'man find' for details.

-dave
Darrel Louis
Honored Contributor

Re: lmit file size

Hi,

Look at the following url:
http://packages.qa.debian.org/l/logrotate.html
Logrotate is a tool which will rotate your logfiles.

Regards

Darrel
peterchu
Super Advisor

Re: lmit file size

thx reply ,

I check louis's solution , it is quite easy to use


I hv man the logrotate , it seems very good , but I am not too understand how to use it , I find the below example , I want to ask if I want to compress the /var/log/messages and mail to administrator when it reach 100M size , how to set it ? thx in advance.


# sample logrotate configuration file
compress

/var/log/messages {
rotate 5
weekly
postrotate
/sbin/killall -HUP syslogd
endscript
}
Darrel Louis
Honored Contributor

Re: lmit file size

Hi,

For messages you can set the following in the /etc/logrotate.conf file:
/var/adm/messages {
daily
size=1000k
rotate 4
}

Don't know if your messages file will be filled that much.

Regards

Darrel