Skip to content

Instantly share code, notes, and snippets.

@Lixivial
Created January 17, 2010 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lixivial/279226 to your computer and use it in GitHub Desktop.
Save Lixivial/279226 to your computer and use it in GitHub Desktop.
import old tarball'd logs into a new awstats config.
#!/bin/bash
# old_logs.sh -- A simple import script to import old tarball logs into a new awstats site config.
# by Lixivial (Jesse Pearson)
# contact: jesall@gmail.com
# or irc.quakenet.org/#prae.nexuiz
#
# Script arguments:
#
# config -- awstats config name sans .conf
# access_log -- the path to the access log with wildcards
# [timeout in seconds] -- optional timeout value to allow awstats processing lag, default 5 seconds.
config_name=""
log_path=""
sleep_time=""
function getParameters() {
if [ "$1" == "" ] || [ "$1" == "--help" ] || [ "$2" == "" ] || [ "$2" == "--help" ] || [ "$3" == "--help" ] || [ "$4" == "--help" ]; then
printHelp
exit 1;
else
config_name="$1"
log_path="$2"
if [ "$3" == "" ]; then
sleep_time=5
else
sleep_time=$3
fi
fi
}
function checkFileType() {
local __log_file="$1"
local __result=`file "$__log_file"`
if [[ $(echo "$__result" | grep "ASCII") != "" ]]; then
echo "text"
else
if [[ $(echo "$__result" | grep "gzip") != "" ]]; then
echo "gzip"
else
if [[ $(echo "$__result" | grep "symbolic") != "" ]]; then
echo "symlink"
fi
fi
fi
}
function performImport() {
local __config_name="$1"
local __log_path="$2"
local __sleep_time=$3
local __type=""
local __files=$(ls -rt $__log_path)
for log in ${__files}
do
__type=$(checkFileType "${log}")
echo "log: $log"
echo "type: $__type"
case $__type in
"text")
cat $log > /tmp/access_log
;;
"gzip")
zcat $log > /tmp/access_log
;;
"symlink")
continue
;;
*)
continue
esac
sleep $__sleep_time
/usr/lib/cgi-bin/awstats.pl -config=$__config_name -LogFile=/tmp/access_log -update
sleep $__sleep_time
done
}
function printHelp() {
echo "Usage: old_logs.sh config access_log [timeout in seconds]
ex: old_logs.sh www.nexfiles.com /var/log/apache2/nexfiles/logs/nexfiles.com/http/access\* 5"
}
getParameters "$1" "$2" "$3" $4
performImport "$config_name" "$log_path" $sleep_time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment