#!/bin/bash LOGDIR='/var/log/httpd' REPODIR='/home/www/myhome/visitors' IP2HOST='/usr/local/bin/ip2host' VISITORS='/usr/local/bin/visitors' WeekDay=$(date +%a) TopDay=$(date +%d) YesDate=$(date --date '1 days ago' | awk '{print $3}') YesMonth=$(date --date '1 days ago' | awk '{print $2}') YesYear=$(date --date '1 days ago' | awk '{print $6}') PreYear=$(date --date '1 months ago' | awk '{print $6}') PreMonth=$(date --date '1 months ago' | awk '{print $2}') FNameDate=$(date --date '1 months ago' | awk '{print $2 $6}') if [ "$WeekDay" = Mon ] ; then if [ -f $REPODIR/fqdn_access_log.5 ] ; then rm -f $REPODIR/fqdn_access_log.5 fi if [ -f $REPODIR/fqdn_access_log.4 ] ; then mv $REPODIR/fqdn_access_log.4 $REPODIR/fqdn_access_log.5 fi if [ -f $REPODIR/fqdn_access_log.3 ] ; then mv $REPODIR/fqdn_access_log.3 $REPODIR/fqdn_access_log.4 fi if [ -f $REPODIR/fqdn_access_log.2 ] ; then mv $REPODIR/fqdn_access_log.2 $REPODIR/fqdn_access_log.3 fi if [ -f $REPODIR/fqdn_access_log.1 ] ; then mv $REPODIR/fqdn_access_log.1 $REPODIR/fqdn_access_log.2 fi if [ -f $REPODIR/fqdn_access_log ] ; then mv $REPODIR/fqdn_access_log $REPODIR/fqdn_access_log.1 fi grep $YesDate/$YesMonth/$YesYear $LOGDIR/access_log.1 > $REPODIR/log_sun_grep cat $REPODIR/log_sun_grep > $REPODIR/access_log_sun cat $LOGDIR/access_log >> $REPODIR/access_log_sun $IP2HOST < $REPODIR/access_log_sun > $REPODIR/fqdn_access_log rm -f $REPODIR/log_sun_grep rm -f $REPODIR/access_log_sun fi if [ "$WeekDay" != Mon ] ; then grep $YesDate/$YesMonth/$YesYear $LOGDIR/access_log > $REPODIR/log_plus_grep $IP2HOST < $REPODIR/log_plus_grep > $REPODIR/fqdn_plus_log cat $REPODIR/fqdn_plus_log >> $REPODIR/fqdn_access_log rm -f $REPODIR/log_plus_grep rm -f $REPODIR/fqdn_plus_log fi $VISITORS -A -H -m 100 $REPODIR/fqdn_access_log | nkf -w -m0 > $REPODIR/repo-days.html chown apache:apache $REPODIR/repo-days.html chmod g-w,o-rw $REPODIR/repo-days.html if [ "$TopDay" = 01 ] ; then cat $REPODIR/fqdn_access_log* > $REPODIR/access_log_month grep $PreMonth/$PreYear $REPODIR/access_log_month > $REPODIR/log_month_grep $VISITORS -A -H -m 100 $REPODIR/log_month_grep | nkf -w -m0 > $REPODIR/$FNameDate.html chown apache:apache $REPODIR/$FNameDate.html chmod g-w,o-rw $REPODIR/$FNameDate.html rm -f $REPODIR/access_log_month rm -f $REPODIR/log_month_grep fi exit