[olug] Unix Tip: TRIMMING THE LOG

Unix Guru Universe listserv at ugu.com
Thu May 29 06:55:20 UTC 2003


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

			      UNIX GURU UNIVERSE 
			         UNIX HOT TIP

			Unix Tip 1974 - May 28, 2003

		    http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


TRIMMING THE LOG 


Various unix processes can 
produce fast growing logs that 
sometimes need to be trimmed 
instead of deleted, for reference 
or troubleshooting. And you 
likely have no desire to edit the 
files. Here is a handy ksh 
script that will quickly trim 
the log so it keeps recent 
information and lets you keep as 
many lines as you think you might 
need. I call it trimlog: 

#! /bin/sh 
# trimlog 
filesize=`cat $1|wc -l` 
trim=`expr $filesize - $2` 
if [ $trim -gt 0 ] 
then 
sed "1,$trim d" $1 > /tmp/$1 
mv /tmp/$1 $1 
echo $1 trimmed by $trim lines 
fi 

Use it by feeding in the name of 
the log you want to trim followed 
by the number of lines you want to 
keep: 

# trimlog oracle_listener.log 10000 


Of course you can't use it in 
the /tmp directory. There are 
probably newer and more efficient 
ways to do this, but this works. 


--------------------------------------------------------------------------
To Subscribe:    http://www.ugu.com/sui/ugu/show?tip.subscribe
To Unsubscribe:  http://www.ugu.com/sui/ugu/show?tip.unsubscribe
To Submit A Tip: http://www.ugu.com/sui/ugu/show?tip.today

==========================================================================
DISCLAIMER: All UNIX HOT TIPS ARE OWNED BY THE UNIX GURU UNIVERSE AND ARE
NOT TO BE SOLD, PRINTED OR USED WITHOUT THE WRITTEN CONSENT OF THE UNIX 
GURU UNIVERSE. ALL TIPS ARE "USE AT YOUR OWN RISK". UGU  ADVISES THAT 
ALL TIPS BE TESTED IN A NON-PRODUCTION DEVELOPMENT ENVIRONMENT FIRST.

Unix Guru Universe - www.ugu.com - tips at ugu.com - Copyright 1994-2001
==========================================================================



More information about the OLUG mailing list