Purging Logs

Many programs maintain some variety of logs. Often, much of the information in the logs is redundant or just useless. The program shown in Listing 37.7 removes all lines from a file that contain a particular word or phrase, so lines that you know are not important can be purged. For example, you might want to remove all the lines in the Apache error log that originate with your test client machine because you know those error messages were produced during testing.

Listing 37.7. Purging Log Files

#!/usr/bin/perl# Be careful using this program!# This will remove all lines that contain a given word# Usage:  remove <word> <file>$word=@ARGV[0];$file=@ARGV[1];if ($file)  {  # Open file for reading  open (FILE, "$file") or die "Could not ...

Get Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.