Now on ScienceBlogs: Oh, no! School wi-fi is making our kids sick! (2012 edition)

ScienceBlogs Book Club: Inside the Outbreaks

Greg Laden's Blog

Evolution, Life Sciences, Science Education, Human Evolution, and Stuff

Hornbill170.jpg Looking for stuff about birds?

Darwing_Face.jpg Learn more about Charles Darwin and his work.

Lion_mane170.jpg Lean more about lions

Congo_sidebar.jpg An archaeological expedition to the Congo


The Skeptical Search Engine


Nature Blog Network
Climate Defense Fund


The contents of Greg Laden's Blog are copyrighted by Greg Laden.

Recent Comments

Search

Profile


Click on "About" for the big picture, and "Archives" for the details.


Recent Posts

Blogroll

If you don't see yourself on my blogroll, just drop me a line and let me know. I'll add you.*
*Assuming that I'm on your blogroll, of course!

Archives

« Some great Sunday reading. | Main | Today's Sunday Bible Reading Ezekiel 25:17 »

How to keep your server's hard drive from filling up with log files.

Category: Computer TricksLinuxOpenSource
Posted on: October 25, 2009 12:11 PM, by Greg Laden

Log files are good because they log stuff, so you can find out what's been going on and troubleshoot. But they tend to accumulate and can actually fill up your hard drive. Most Linux distros have automatic log file management for common system logs, but if you are running something on your server that keeps a log not thusly covered, you may have to manage that log file by yourself.

You could have a cron entry that simply deletes the log files in question every week or so, but then you lose the benefits of having a log file to begin with. The usual solution to this is called "Log Rotation" and it works like this:

The usual solution to the space problem is to rotate your log files. (We'll see an unusual solution later in this section.) After a specific duration has passed or a file size has been reached, the current log file is moved to another name, e.g., logfile.0. The logging process is then continued into an empty file. At the next interval or limit, we repeat the process, first moving the backup file (logfile.0 ) to another name (like logfile.1). This process is repeated until a set number backup files have been created. The oldest backup file at that point is deleted.

There's a script or two here to make this work. Here's another script (scroll down to see it), and here's a bash script that uses cron to rotate log files.

Share on Facebook
Share on StumbleUpon
Share on Facebook
Find more posts in: Technology

TrackBacks

TrackBack URL for this entry: http://scienceblogs.com/mt/pings/123186

Comments

1

Why not just use logrotate? (http://www.linuxconfig.org/Logrotate)

Easy to manage different schedules for different logs, run commands before or after (e.g. to make an application reopen its logfiles)

Posted by: Jonathan | October 25, 2009 4:36 PM

2

As an addendum to the previous comment, this is what most distros use to manage their own logs (as you elude to in the post), but the rules for it are really not hard to write, probably easier than an adhoc script.

Posted by: Jonathan | October 25, 2009 4:39 PM

Post a Comment

(Email is required for authentication purposes only. On some blogs, comments are moderated for spam, so your comment may not appear immediately.)





ScienceBlogs

Search ScienceBlogs:

Go to:

Advertisement
Follow ScienceBlogs on Twitter

© 2006-2011 ScienceBlogs LLC. ScienceBlogs is a registered trademark of ScienceBlogs LLC. All rights reserved.