Web Techniques Magazine
April 1996
Volume 1, Issue 1





 



#!/usr/local/bin/perl # File: cycle.pl # Basic log cycling utility #Change these path names for your system $LOGPATH='/usr/local/etc/httpd/logs'; $GZIP = '/bin/gzip'; $PIDFILE = 'httpd.pid'; #!/usr/local/bin/perl # File: cycle.pl # Basic log cycling utility # Change these path names for your system $LOGPATH='/usr/local/etc/httpd/logs'; $GZIP = '/bin/gzip'; $PIDFILE = 'httpd.pid'; # Add the names of the logs you want to cycle to this list @LOGNAMES=('access_log','error_log', 'referer_log','agent_log'); # Add the names of the logs you want to archive to this array /ARCHIVE=('access_log',1, 'error_log',1); # This is the number of log files to keep around before # archiving or deleting. $MAXCYCLE = 4; #------ You shouldn't have to change this ------ chdir $LOGPATH; # Change to the log directory foreach $filename (@LOGNAMES) { system "$GZIP -c $filename.$MAXCYCLE >> $filename.gz" if $ARCHIVE{$filename}; for ($s=$MAXCYCLE;$s--;$s>=0) { $oldname = $s ? "$filename.$s" : $filename; $newname = join(".",$filename,$s+1); rename $oldname,$newname if -e $oldname; } } kill 'HUP',`cat $PIDFILE`;

(back)


Copyright Web Techniques, all rights reserved.