Date: Thu, 8 Mar 2001 08:21:43 -0000 From: Paul Walsh To: Philip Hazel Subject: exicyclog I hope you don't mind, but I've used the logic in exicyclog as the basis for a Perl script which is intended to be configurable to cater for any number of log files (as may be created by system filters). I'm attaching the program for your consideration as I thought it might prove useful to other users of Exim. #! /usr/local/bin/perl # exicylog2 - Perl script to take copies of logfiles, appending a number to the # backup copies and compressing all but the latest copy. # This script was derived from the exicyclog shell script supplied # with Exim # This version (c) 2001 University of Central England # NOTE: Variables with UPPERCASE names may require modification to cater for # different installations $KEEP = 10; # No. of copies of logs to keep $COMPRESS = "/usr/local/bin/gzip"; # path to compression program $SUFFIX = "gz"; # suffix used by compression program $LOGDIR = "/usr/exim/logs"; # directory where exim logs are stored # Array of log names to cycle through. This can be extended to cater for other # logfiles written to LOGDIR (those produced by a system filter, for example) @LOGS = ("main","reject","panic"); $x=chdir($LOGDIR); # cd to log directory # For each log type, construct logfile name then work through copies of logs from # the oldest to the last but one copy foreach $log (@LOGS) { # logfile name will depend on what was set in Local/Makefile when exim was built, # so this will require modification accordingly $LOGFILE=sprintf("%s.log",$log); # Only work through old copies if there is a current log file if (-e $LOGFILE) { foreach $i (reverse 2 .. $KEEP){ $j = $i - 1; # Determine filenames of copy and compressed copy. Copies with a suffix # less than 100 have a 2-digit suffix (as do those produced by exicyclog) if ($i < 100){ $file = sprintf("%s.%02d",$LOGFILE,$i); $Compressed_file = sprintf("%s.%02d.%s",$LOGFILE,$i,$SUFFIX); } else { $file = sprintf("%s.%03d",$LOGFILE,$i); $Compressed_file = sprintf("%s.%03d.%s",$LOGFILE,$i,$SUFFIX); } if ($j < 100) { $Nextfile = sprintf("%s.%02d",$LOGFILE,$j); $Compressed_Nextfile = sprintf("%s.%02d.%s",$LOGFILE,$j,$SUFFIX); } else { $Nextfile = sprintf("%s.%03d",$LOGFILE,$j); $Compressed_Nextfile = sprintf("%s.%03d.%s",$LOGFILE,$j,$SUFFIX); } # If we're working with the oldest copy, remove it (or its compressed version if there is one) if ($i == $KEEP) { $x = `rm $file` if -e $file; $x = `rm $compressed_file` if -e $compressed_file; } else { # Rename copy of logfile and compress it, thus logfile.01 becomes logfile.02 # and is then compressed, resulting in logfile.02.gz (asuming gzip is being used) if (-e $Nextfile) { $x = `mv $Nextfile $file`; $x = `$COMPRESS $file`; } else { if ( -e $compressed_Nextfile) { $x = `mv $compressed_Nextfile $compressed_file`; } } } } # Finally we rename the current log file, appending .01 to the filename. # Leave the file uncompressed to ease examination $x = `mv $LOGFILE $LOGFILE.01`; } }