Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!jarthur!uunet!mcsun!ukc!cf-cm!bharat From: bharat@computing-maths.cardiff.ac.uk (Bharat Mediratta) Newsgroups: comp.sources.wanted Subject: Re: logfile management program needed ... Keywords: logfile Message-ID: <1991May9.133329.10815@cm.cf.ac.uk> Date: 9 May 91 13:33:29 GMT References: <100@morwyn.UUCP> Sender: news@cm.cf.ac.uk (USENET News System) Organization: University of Wales College of Cardiff Lines: 46 In article <100@morwyn.UUCP> forrie@morwyn.UUCP (Forrie Aldrich) writes: >I'm looking for a program that can be used to trim (regularly) >logfiles such as /usr/adm/sulog and /usr/spool/smail/log/logfile, >and the such that accumalte frequently ... yet retain the last >few entries while deleting the rest... > >I've heard about a program like this somewhere, but haven't been >able to find it. I use a shell script to trim my internal logfiles (.where, mail_log, etc.) and I find it pretty useful. Cheers, Bharat --- CUT HERE -- #!/bin/csh -f set name = $argv[1] set tmp = /tmp/$name set max = 200 # Max number of lines in log before it's trimmed set min = 80 # what the log's trimmed down to set size = `wc -l $name | awk '{print $1}'` if ("`expr $size \> $max`" == "1") then tail -$min < $name > $tmp if (-e $tmp) then if (`wc -l $tmp | awk '{print $1}'` == $min) then cp $tmp $name /bin/rm -f $tmp else echo "Error: Processed file incorrectly." endif else echo "Error: Couldn't create temporary file." endif endif -- CUT HERE -- -- | Bharat Mediratta | JANET: bharat@cm.cf.ac.uk | +--------------------+ UUNET: bharat%cm.cf.ac.uk%cunyvm.cuny.edu@uunet.uucp | |On a clear disk... | uk.co: bharat%cm.cf.ac.uk%cunyvm.cuny.edu%uunet.uucp@ukc| |you can seek forever| UUCP: ...!uunet!cunym.cuny.edu!cm.cf.ac.uk!bharat |