Ollie (saber_rider) wrote,
Ollie
saber_rider

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
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments