1833779 Members
2106 Online
110063 Solutions
New Discussion

Trimming log files

 
roadrunner_1
Regular Advisor

Trimming log files

I am trying to trim cron log files which is about 120M
I am using the following command:
tail -5000 log > log.old and then the idea is to zero the original log file.

But the tail command takes only the last 365 lines and the same thing happens with the tail -n option. Is there any limitation for the number of lines with the tail command or can any one tell me another method to trim the file
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: Trimming log files

From man tail:

"Tails relative to end-of-file are stored in a 20-Kbyte buffer, and
thus are limited in length."


Pete

Pete
Tom Jackson
Valued Contributor

Re: Trimming log files

Hi:

I found this with man tail:

Tails relative to end-of-file are stored in a 20-Kbyte buffer, and
thus are limited in length. Therefore, be wary of the results when
piping output from other commands into tail.


Tom
John Poff
Honored Contributor

Re: Trimming log files

Hi,

As Pete mentioned, there is a buffer limit for 'tail'. Take a look at these two threads. I'm pretty sure there are some scripts in there that will take care of log files:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x026250011d20d6118ff40090279cd0f9,00.html

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x836cc1c4ceddd61190050090279cd0f9,00.html



JP
James R. Ferguson
Acclaimed Contributor

Re: Trimming log files

Hi:

Yes, 'tail' has definite buffer limitations. The better choice is to use 'sed' to chop. Calculate from where you want to delete, for instance with 'wc -l filename' and then do:

# sed -e '1000,$!d' infile > outfile

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Trimming log files

Hi (again):

Sorry, I didn't quit finish the above. I suggested using 'wc -l' to deduce the size of your logfile and then inferred computing some line-number to which you want to trim. The example I gave was:

# sed -e '1000,$!d' infile > outfile

Obviously, that's OK for static values. To use a calculated line number, call it "N", change the above to:

# N=1000 #...or whatever, however derived...
# sed -e "$N,$"!d infile > outfile

...Note the use of double quotes to allow shell expansion.

Regards!

...JRF...
Jeff Schussele
Honored Contributor

Re: Trimming log files

Hi,

To just zero the file do

#> /var/adm/cron/log

Note that standard log files can also be trimmed using SAM as follows:

sam -> Routine Tasks -> System Log Files -> highlight /var/adm/cron/log -> Actions -> Trim

And there are several trim options available. You can also set a unique size to key the actions on.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!