Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have three sites on my server and their logs (Apache logs) are in their root folder not in /var/log. I need a script that rotates the access_log and error_log base on their file size for example rotates them when their file size exceeds 1G .

Server's OS is Ubuntu.

I have a basic skill of shell programing but good talent in learing ;) would you help me in this issue?

share|improve this question

migrated from Jun 25 '11 at 10:56

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

up vote 3 down vote accepted

logrotate can be configured tn only rotate when logs exceed a certain size, see the minsize option. Typically logrotate runs daily though, if you wanted to rotate when the logfile was more or less exactly 1GB, you might need a script which watches the logfile and triggers logrotate when it exceeds your limit.

Alternatively, you could stick with daily rotation of smaller logfiles, but have a postrotate script which concatenates the rotated logs together into 1GB clumps of data.

share|improve this answer

You can use managelogs exactly for that.
It will automatically rotate the logs when the limit is reached.
It also has other neat features like directly writing to compressed files, keep a larger amount of archive files, etc.

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.