Operating System - HP-UX
1826797 Members
2593 Online
109703 Solutions
New Discussion

/var/adm/cron/log file size reduction

 
SOLVED
Go to solution
M.Dellinger
New Member

/var/adm/cron/log file size reduction

Hi,
Years ago there were shell programs like logchecker that we could run in cron to check and reduce the size of files like /var/adm/cron/log. Does HP-UX still have anything like that or do we need to write our own? I'm running 10.20
Thanks!
5 REPLIES 5
Alan Meyer_4
Respected Contributor
Solution

Re: /var/adm/cron/log file size reduction

There is a logrotate tool that you can find here

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/logrotate-2.5/
" I may not be certified, but I am certifiable... "
Mel Burslan
Honored Contributor

Re: /var/adm/cron/log file size reduction

TRIMpct=70 # change this as you wish
FILELENGTH=`cat /var/adm/cron/log|wc -l`
LINES2TRIM=`echo ${TRIMpct}*(${FILELENGTH}/100)`
sed -e "1,${LINES2TRIM}d" /var/adm/cron/log >/tmp/tmplog.file
cat /tmp/tmplog.file > /var/adm/cron/log


this should reduce the size of a 10,000 line log file to 3,000 lines. Change the value of TRIMpct variable to adjust how much you want to trim from the top.

hope this helps

PS. Don't use head or tail commands as they do not work well on files of large sizes.
________________________________
UNIX because I majored in cryptology...
Steven E. Protter
Exalted Contributor

Re: /var/adm/cron/log file size reduction

Logrotate is your best bet. Its build into many Linux distributions and works well.

Where I was not permitted to install this, I had a program cron ran that looked like this:

cp $logfile $archive_location
rc=$?
if [ $rc = 0 ]
then
> $logfile
fi


That keeps the filesize under control assuming your archive location is good. If course you need to allocate space to store the copies.

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
M.Dellinger
New Member

Re: /var/adm/cron/log file size reduction

Simple shells like this used to be included with a UNIX OS package, but I see it's changed to where you must supply your own. I plan on using one of the above suggestions. Thank you!
M.Dellinger
New Member

Re: /var/adm/cron/log file size reduction

Thanks. I plan on using logrotate with possible adjustments.