?

Log in

No account? Create an account
October 2013   01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Sir Squid
Posted on 2013.06.05 at 22:06
How I spent my afternoon: write up a script to automatically update my pageview stats. Daily.

I accidentally deleted it once, but managed to rewrite it shortly, having had all the bugs worked out already.

#!/bin/sh

# define a default working directory
dirhome="/tmp/netstats"

# make some useful directories
mkdir -p $dirhome/null
mkdir -p $dirhome/gallery
mkdir -p $dirhome/stats
mkdir -p $dirhome/stats/gallery

# get updated logs
rsync -qa username@server.com:~/logs/gallery*.gz $dirhome/gallery/ > /dev/null 2>&1
rsync -qa username@server.com:~/logs/server*.gz $dirhome/null/ > /dev/null 2>&1

# get rid of stale files
rm -f $dirhome/stats/webalizer.*
rm -f $dirhome/stats/*.png
rm -f $dirhome/stats/*.html

# do the analysis
if [ -f $dirhome/null/server.com-Dec-2012.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Dec-2012.gz
fi
if [ -f $dirhome/null/server.com-Jan-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Jan-2013.gz
fi
if [ -f $dirhome/null/server.com-Feb-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Feb-2013.gz
fi
if [ -f $dirhome/null/server.com-Mar-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Mar-2013.gz
fi
if [ -f $dirhome/null/server.com-Apr-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Apr-2013.gz
fi
if [ -f $dirhome/null/server.com-May-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-May-2013.gz
fi
if [ -f $dirhome/null/server.com-Jun-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Jun-2013.gz
fi
if [ -f $dirhome/null/server.com-Jul-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Jul-2013.gz
fi
if [ -f $dirhome/null/server.com-Aug-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Aug-2013.gz
fi
if [ -f $dirhome/null/server.com-Sep-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Sep-2013.gz
fi
if [ -f $dirhome/null/server.com-Oct-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Oct-2013.gz
fi
if [ -f $dirhome/null/server.com-Nov-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Nov-2013.gz
fi
if [ -f $dirhome/null/server.com-Dec-2013.gz ]
then
webalizer -p -n "server.com" -o $dirhome/stats $dirhome/null/server.com-Dec-2013.gz
fi

# get rid of stale files
rm -f $dirhome/stats/gallery/webalizer.*
rm -f $dirhome/stats/gallery/*.png
rm -f $dirhome/stats/gallery/*.html

# do the analysis
if [ -f $dirhome/gallery/gallery.server.com-Dec-2012.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Dec-2012.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Jan-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Jan-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Feb-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Feb-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Mar-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Mar-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Apr-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Apr-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-May-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-May-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Jun-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Jun-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Jul-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Jul-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Aug-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Aug-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Sep-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Sep-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Oct-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Oct-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Nov-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Nov-2013.gz
fi
if [ -f $dirhome/gallery/gallery.server.com-Dec-2013.gz ]
then
webalizer -p -n "gallery.server.com" -o $dirhome/stats/gallery $dirhome/gallery/gallery.server.com-Dec-2013.gz
fi


# upload the results back to the web server
rsync -va $dirhome/stats/ username@server.com:~/public_html/stats/dynamic > /dev/null 2>&1


exit 0

Previous Entry  Next Entry