#!/bin/ksh # # Rotates server log files and archives the old logfiles. # Does not affect users who may be connected to the server. # # The script to analyze the logfile RUNHA_CMD=/usr/local/bin/run-ha # The script to resolve IP numbers IPRES_CMD=/usr/local/bin/ipresolve IPRES_OPTS="-d /var/tmp/DNS-data" # SERVER_ROOT contains all configuration files SERVER_ROOT="/var/netscape/fasttrack" # Rotate these logfiles LOGS='access errors' integer MON YEAR typeset -Z2 MON typeset -Z4 YEAR eval $(date "+MABB='%B' MON='%m' YEAR='%Y'") ((MON=$MON-1)); [ $MON -eq 0 ] && { MON="12"; ((YEAR=$YEAR-1)); } LOGDIR="log$YEAR" cd $SERVER_ROOT || { echo "panic: can't cd into $SERVER_ROOT" 1>&2; exit 1; } # Rotate all logfiles, inform the server of the chance for server in httpd-*; 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 # Wait 20 minutes to not disturbe other cron jobs starting at 00:00, # then resolve IP numbers into hostnames and run the analyzer to # "finalize" the statistics for the previous (old) month. sleep 1200 # Now we resolve the logfile and produce a gzip'ed summary. # This usually takes a long time and just in case we need # the logfiles more than once, we save the resulting data # with all resolved names. for server in httpd-*; do (cd $server/logs/$LOGDIR $IPRES_CMD $IPRES_OPTS -o access.$MON.gz access.$MON && \ rm -f access.$MON) done # Now run http-analyze through run-ha $RUNHA_CMD $MON $YEAR # Clean the DNS database from entries older than 90 days. # Since we save resolved data, the database helps only to # speed up queries for IP numbers found in the actual # (current) logfile. However, it helps to speed up the # resolving process for the current month, so we keep # last 31 days of data. $IPRES_CMD $IPRES_OPTS -c 32days exit 0