Skip to content

Instantly share code, notes, and snippets.

@wildintellect
Created August 23, 2012 20:23
Show Gist options
  • Save wildintellect/3441213 to your computer and use it in GitHub Desktop.
Save wildintellect/3441213 to your computer and use it in GitHub Desktop.
Bash process old apache logs with awstats
#!/bin/bash
# Alex Mandel 2011
# Apache 2.0 License
#Script outline for updating awstats from historical logs
#Take start number of oldest log via arguments
# grass.osgeo.org
configfile=$1
# grass-access.log
apachelogbase=$2
countdown=$3
# 10 is default , -20 is high priority
nice=$4
#While number != 1 do
#If log names have a date format then we need to sort by date and start with the oldest incrementing through the list
while [ $countdown -gt 1 ]
do
sudo nice -n $nice perl /usr/lib/cgi-bin/awstats.pl -config=$configfile -LogFile="gzip -cd /var/log/apache2/$apachelogbase.$countdown.gz |" -update
#echo "gzip -cd /var/log/apache2/$apachelogbase.$countdown.gz |"
countdown=$(( $countdown - 1 ))
done
#number-1
#repeat
if [ $countdown -eq 1 ]; then
sudo nice -n $nice perl /usr/lib/cgi-bin/awstats.pl -config=$configfile -LogFile="/var/log/apache2/$apachelogbase.1" -update
fi
#the last log will get picked up by cron job, ex the current log yet to be rotated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment