1752756 Members
4814 Online
108789 Solutions
New Discussion юеВ

Re: Trim Log Files.

 
SOLVED
Go to solution
Bill Hassell
Honored Contributor

Re: Trim Log Files.

Here is a sample logtrim.conf configuration file.


Bill Hassell, sysadmin
Geoff Wild
Honored Contributor

Re: Trim Log Files.

I'm with Bill - just copy the file then zero out the original

cp -p syslog.log syslog.log.1

> syslog.log

Or install logrotate:

http://hpux.ee.ualberta.ca/hppd/hpux/Sysadmin/logrotate-2.5/

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sajjad Shafi
Advisor

Re: Trim Log Files.


content of trimlog.sh

filesize=`cat $1 | wc -l`
trim=`expr $filesize - $2`
if [ $trim -gt 0 ]
then
sed "1,$trim d" $1 > $1TMP
mv $1TMP $1
echo $1 trimmed by $trim line
fi

usage:
for example you like to delete 100 lines of syslog.log
u need to run the the shell in following way

trimlog.sh syslog.log 100