Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a quite large apache logfile (2,5 G). Its that big because i havent used logrotate until now. Now the logs get rotated corretly but i want the rotation (one logfile per month) for the time until now so i have to "rotate" the old logfile.

Does anyone know how i could do that ? (some script that splits my logfile per month ?)

Thanks in advance,

Nicolas

share|improve this question
add comment

migrated from stackoverflow.com Feb 27 '12 at 3:50

This question came from our site for professional and enthusiast programmers.

2 Answers

Use awk to find the month boundaries, then use csplit to split by context.

sample data:

1-1  ...
1-15 ...
1-30 ...
2-1  ...
2-15 ...
2-29 ...
3-2  ...
3-20 ...

run command

$ cat log | awk -F- 'x!=$1{x=$1; print "MONTH"}1' | csplit - /MONTH/ '{*}'

delete first line

$ sed -i 1d xx*
share|improve this answer
add comment

LoadModule log_rotate_module modules/mod_log_rotate.so

CustomLog site.%m-.access.log

http://www.sitebuddy.com/mod_log_rotate

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.