#!/bin/ksh # # $Id: rotate-httpd,v 1.2 1998/01/18 12:30:31 stefan Exp $ # # Rotate server log files and archive the old logfiles. # Does not affect users who may be connected to the server. # # Copyright © 1996-1998 by Stefan Stapelberg/RENT-A-GURU®, # # SRVROOT is the name of the ServerRoot directory. SRVROOT=/usr/ns-home # CFGFILE defines the name of the config file for this server. CFGFILE=analyze.conf # ANALYZE contains the name of the executable program. ANALYZE=/usr/local/bin/http-analyze # SRVLIST contains the names of all SERVER_ROOT configuration directories SRVLIST='httpd-80' # Add here any additional logfiles you want rotated. LOGS='access errors secure' typeset -i MON YEAR typeset -Z2 MON eval $(date "+MABB='%B' MON='%m' YEAR='%Y'") ((MON=$MON-1)); [ $MON -eq 0 ] && { MON="12"; ((YEAR=$YEAR-1)); } LOGDIR="log$YEAR" cd $SRVROOT || { echo "panic: can't cd into $SRVROOT" 1>&2; exit 1; } for server in $SRVLIST; do (cd $server/logs [ ! -d "$LOGDIR" ] && { mkdir $LOGDIR; } for file in $LOGS; do [ -f $file ] && { mv $file $LOGDIR/$file.$MON; } echo "$server/logs/$file saved in $LOGDIR/$file.$MON" 1>&2 done) $server/restart done # Now run http-analyze for each server. For each server, # a configuration file must exist under the ServerRoot. for server in $SRVLIST; do (cd $server; [ -s $CFGFILE ] && \ { $ANALYZE -m -c $CFGFILE logs/$LOGDIR/$file.$MON; \ $ANALYZE -m -c $CFGFILE; }) done