run_goaccess
· 1.8 KiB · Text
Raw
#!/bin/bash
LOG_DIR="/var/log/apache2/vhosts/access_logs/"
VHOST_BASE="/var/www/"
STATS_OUT_DIR="/stats/"
BOOTSTRAP=0
for DIR in $(find /var/www/ -maxdepth 2 -name 'public_html' -type d); do
VHOST=$(basename $(echo $DIR | sed "s/\/public_html.*//"))
if [ "$BOOTSTRAP" == "1" ]; then
[ ! -d $VHOST_BASE/$VHOST/goaccess-db ] && mkdir -p $VHOST_BASE/$VHOST/goaccess-db
[ ! -d $VHOST_BASE/$VHOST/stats ] && mkdir -p $VHOST_BASE/$VHOST/stats
[ $(grep -c "Alias /stats" /etc/apache2/sites-available/"$VHOST"_settings) -le 0 ] && sed -i "/Alias \/phpmyadmin.*/a \\\tAlias /stats \"\/var\/www\/$VHOST\/stats\/\"" /etc/apache2/sites-available/"$VHOST"_settings
if [ ! -f /var/www/"$VHOST"/stats/.htaccess ]; then
USER="$(stat -c "%U" "$VHOST_BASE/$VHOST/public_html" )"
printf "AuthName \"restricted stuff\"\nAuthType Basic\nAuthUserFile /etc/apache2/users\n\nrequire user focus $USER" > $VHOST_BASE/$VHOST/stats/.htaccess
fi
for FILE in $(find $LOG_DIR -name $VHOST-access.log.*.gz); do
zcat $FILE | goaccess \
--agent-list \
--anonymize-ip \
--persist \
--restore \
--config-file /etc/goaccess/goaccess.conf \
--db-path "$VHOST_BASE/$VHOST/goaccess-db" \
--log-format COMBINED \
--output "$VHOST_BASE/$VHOST/$STATS_OUT_DIR/index.html" \
-
done
fi
LOGFILES=()
for ext in log log.1; do
logfile="$LOG_DIR/$VHOST-access.$ext"
[ -e "$logfile" ] && LOGFILES+=("$logfile")
done
if [ ${#LOGFILES[@]} -eq 0 ]; then
echo "No log files in '$LOGDIR'"
else
goaccess \
--agent-list \
--anonymize-ip \
--persist \
--restore \
--config-file /etc/goaccess/goaccess.conf \
--db-path "$VHOST_BASE/$VHOST/goaccess-db" \
--log-format "COMBINED" \
--output "$VHOST_BASE/$VHOST/$STATS_OUT_DIR/index.html" \
"${LOGFILES[@]}"
fi
done
| 1 | #!/bin/bash |
| 2 | |
| 3 | LOG_DIR="/var/log/apache2/vhosts/access_logs/" |
| 4 | VHOST_BASE="/var/www/" |
| 5 | STATS_OUT_DIR="/stats/" |
| 6 | BOOTSTRAP=0 |
| 7 | |
| 8 | for DIR in $(find /var/www/ -maxdepth 2 -name 'public_html' -type d); do |
| 9 | VHOST=$(basename $(echo $DIR | sed "s/\/public_html.*//")) |
| 10 | |
| 11 | if [ "$BOOTSTRAP" == "1" ]; then |
| 12 | [ ! -d $VHOST_BASE/$VHOST/goaccess-db ] && mkdir -p $VHOST_BASE/$VHOST/goaccess-db |
| 13 | [ ! -d $VHOST_BASE/$VHOST/stats ] && mkdir -p $VHOST_BASE/$VHOST/stats |
| 14 | [ $(grep -c "Alias /stats" /etc/apache2/sites-available/"$VHOST"_settings) -le 0 ] && sed -i "/Alias \/phpmyadmin.*/a \\\tAlias /stats \"\/var\/www\/$VHOST\/stats\/\"" /etc/apache2/sites-available/"$VHOST"_settings |
| 15 | if [ ! -f /var/www/"$VHOST"/stats/.htaccess ]; then |
| 16 | USER="$(stat -c "%U" "$VHOST_BASE/$VHOST/public_html" )" |
| 17 | printf "AuthName \"restricted stuff\"\nAuthType Basic\nAuthUserFile /etc/apache2/users\n\nrequire user focus $USER" > $VHOST_BASE/$VHOST/stats/.htaccess |
| 18 | fi |
| 19 | for FILE in $(find $LOG_DIR -name $VHOST-access.log.*.gz); do |
| 20 | zcat $FILE | goaccess \ |
| 21 | --agent-list \ |
| 22 | --anonymize-ip \ |
| 23 | --persist \ |
| 24 | --restore \ |
| 25 | --config-file /etc/goaccess/goaccess.conf \ |
| 26 | --db-path "$VHOST_BASE/$VHOST/goaccess-db" \ |
| 27 | --log-format COMBINED \ |
| 28 | --output "$VHOST_BASE/$VHOST/$STATS_OUT_DIR/index.html" \ |
| 29 | - |
| 30 | done |
| 31 | fi |
| 32 | |
| 33 | LOGFILES=() |
| 34 | for ext in log log.1; do |
| 35 | logfile="$LOG_DIR/$VHOST-access.$ext" |
| 36 | [ -e "$logfile" ] && LOGFILES+=("$logfile") |
| 37 | done |
| 38 | |
| 39 | if [ ${#LOGFILES[@]} -eq 0 ]; then |
| 40 | echo "No log files in '$LOGDIR'" |
| 41 | else |
| 42 | goaccess \ |
| 43 | --agent-list \ |
| 44 | --anonymize-ip \ |
| 45 | --persist \ |
| 46 | --restore \ |
| 47 | --config-file /etc/goaccess/goaccess.conf \ |
| 48 | --db-path "$VHOST_BASE/$VHOST/goaccess-db" \ |
| 49 | --log-format "COMBINED" \ |
| 50 | --output "$VHOST_BASE/$VHOST/$STATS_OUT_DIR/index.html" \ |
| 51 | "${LOGFILES[@]}" |
| 52 | fi |
| 53 | done |
| 54 |