Last active
September 13, 2018 15:56
-
-
Save jkugler/1c675cffd222990edb25bcaba37c5f65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
POSITIONAL=() | |
AWSTATS_PROG=$(which awstats.pl 2> /dev/null) | |
BUILD_STATIC_PROG=$(which awstats_buildstaticpages.pl 2> /dev/null) | |
OUTPUT_DIR="./" | |
while [[ $# -gt 0 ]]; do | |
key="$1" | |
case $key in | |
-a|--awstats-prog) | |
AWSTATS_PROG="$2" | |
shift | |
shift | |
;; | |
-b|--build-static-prog) | |
BUILD_STATIC_PROG="$2" | |
shift | |
shift | |
;; | |
-o|--output-dir) | |
OUTPUT_DIR="$2" | |
shift | |
shift | |
;; | |
*) | |
POSITIONAL+=("$1") # save it in an array for later | |
shift | |
;; | |
esac | |
done | |
set -- "${POSITIONAL[@]}" # restore positional parameters | |
if [[ -z $AWSTATS_PROG ]]; then | |
echo "** awstats.pl not in \$PATH and no --awstats-prog argument provided" | |
exit 1 | |
fi | |
if [[ -z $BUILD_STATIC_PROG ]]; then | |
echo "** awstats_buildstaticpages.pl not in \$PATH and no --build-static-prog argument provided" | |
exit 1 | |
fi | |
if [ "$#" -lt 2 ]; then | |
echo "Usage:"; | |
echo " $0 [--awstats-prog /path/to/awstats.pl] [--build-static-prog /path/to/awstats_buildstaticpages.pl] --output-dir /path/to/output/dir/ domain path_to_config_dir"; | |
exit 1; | |
fi | |
DOMAIN=$1 | |
CONFIG_PATH=$2 | |
DATA_PATH=$(grep '^DirData' ${CONFIG_PATH}/awstats.${DOMAIN}.conf | cut -f 2 -d '=' | tr -d '"' | tr -d "'") | |
cat <<EOF > $OUTPUT_DIR/index.html | |
<html lang="en"> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<title>Statistics for $DOMAIN</title> | |
</head> | |
<body> | |
EOF | |
for full_path in $(ls -1tr $DATA_PATH/awstats*.$DOMAIN.txt); do | |
f=$(basename $full_path) | |
DATE=${f:7:6} | |
MONTH=${DATE:0:2} | |
YEAR=${DATE:2:4} | |
echo "Building ${YEAR}${MONTH}" | |
$BUILD_STATIC_PROG \ | |
-configdir=$CONFIG_PATH \ | |
-config=$DOMAIN \ | |
-awstatsprog=$AWSTATS_PROG \ | |
-dir=$OUTPUT_DIR \ | |
-builddate=${YEAR}${MONTH} \ | |
-year=$YEAR -month=$MONTH | |
echo "<a href=\"awstats.$DOMAIN.${YEAR}${MONTH}.html\">Stats for ${YEAR}-${MONTH}</a></br>" >> $OUTPUT_DIR/index.html | |
done | |
cat <<EOF >> $OUTPUT_DIR/index.html | |
</body> | |
</html> | |
EOF |
Recommend making this change to line 56 to account for AWStats config where DirData is set more than once:
DATA_PATH=$(grep '^DirData' ${CONFIG_PATH}/awstats.${DOMAIN}.conf | tail -n 1 | cut -f 2 -d '=' | tr -d '"' | tr -d "'")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much, I modified the script a little for default domain: https://gist.github.com/alexkuebo/c18b78cfdab1f33bbec66fc823b8626e