#!/usr/bin/bash # # Run http-analyze for all our customers # USAGE="$(basename $0) [-v]" APACHE_CFG=/usr/local/etc/httpd/conf/httpd.conf IR_PATHNAME=/usr/local/bin/ipresolve IR_DATABASE=/var/tmp/DNS HA_PATHNAME=/usr/local/bin/http-analyze HA_CONFNAME=http-analyze.conf DEFMODE="-m3f -F elf -b 102400" SERVERLIST=`sed -n 's/^ServerName[ ][ ]*\(.*\)/\1/p' $APACHE_CFG` SERVERROOT=/www/vhosts ECHO=": " while [ $# -gt 0 ]; do case $1 in -h) echo "Usage: $USAGE"; exit 0 ;; -v) DEFMODE="$DEFMODE $1" ; ECHO=echo ;; -e) ECHO=echo ;; [01][0-9]) MONTH="$1" ;; [012][0-9][0-9][0-9]) YEAR="$1" ;; *) echo "Invalid parameter: $1\nUsage: $USAGE" 1>&2; exit 1 ;; esac shift done if [ -n "$MONTH" ]; then : ${YEAR:=$(date +%Y)} LOGTEMPLATE="log$YEAR/access.$MONTH" fi # change into the root directory of all virtual hosts cd $SERVERROOT || { echo "Couldn't change into directory $SERVERROOT" 1>&2; exit 1; } for server in $SERVERLIST; do # # First, check for the document root with and w/o the prefix "www." # if [ -d www.$server/ ]; then server=www.$server; fi if [ ! -d $server ]; then echo "No document root found for $server in $SERVERROOT" 1>&2 continue fi # absence of logs directory means skip this vhost if [ ! -d $server/logs ]; then continue; fi # select proper logfile if [ -n "$MONTH" ]; then LOGFILE="$server/logs/log$YEAR/access_log.$MONTH" else LOGFILE="$server/logs/access_log" fi if [ ! -s "$LOGFILE" ]; then echo "Can't open the logfile \`$SERVERROOT/$LOGFILE' for vhost $server" 1>&2 continue fi # # Create the statistics directory # STATSDIR=$server/stats if [ ! -d "$STATSDIR" ]; then mkdir $STATSDIR 2>/dev/null; fi if [ ! -d "$STATSDIR" ]; then echo "Can't create directory \`$SERVERROOT/$STATSDIR' for statistics" 1>&2 continue fi # # Generate statistics # $ECHO "Generating new statistics for $server" if [ -f $server/$HA_CONFNAME ]; then $IR_PATHNAME -d $IR_DATABASE $LOGFILE | $HA_PATHNAME $DEFMODE -c $server/$HA_CONFNAME -o $STATSDIR - else $IR_PATHNAME -d $IR_DATABASE $LOGFILE | $HA_PATHNAME $DEFMODE -S $server -o $STATSDIR - fi done exit 0