Skip to content

Instantly share code, notes, and snippets.

@dedeibel
Created May 21, 2016 22:51
Show Gist options
  • Save dedeibel/593906f6ca935697121bfd3fa2b83f07 to your computer and use it in GitHub Desktop.
Save dedeibel/593906f6ca935697121bfd3fa2b83f07 to your computer and use it in GitHub Desktop.
Create a goaccess report with the input of all access logs, including zipped ones in a given range e.g. the last week
#!/bin/bash
set -e
#set -x
# Tested on debian jessie
# Install goaccess
# Define your log format in /etc/goaccess.conf
# e.g log-format %h %^[%d:%^] "%r" %s %b "%R" "%u"
OUTFILE=$1
if [[ -z $OUTFILE ]]; then
echo "$0 OUTFILE"
exit 1
fi
# date output has to match access log
export LC_TIME=C
# Change days to your need
LASTWEEK=`date -d '7 days ago' +%d/%b/%Y`
LOGS_NORMAL=`ls -t -r /var/log/apache2/access.*[!g][!z]`
LOGS_GZ=`ls -t -r /var/log/apache2/access.log*.gz`
OLDEST=`ls -1 -t /var/log/apache2/access.log*.gz | tail -1`
SED_START_LINE="1"
( grep "$LASTWEEK" $OLDEST ) || SED_START_LINE="\\#$LASTWEEK#"
cat <(zcat $LOGS_GZ) <(cat $LOGS_NORMAL) | \
sed -n -e "$SED_START_LINE,$ {/Monit/ d; p}" | \
nice -n 19 goaccess --no-progress -a > "$OUTFILE
@dedeibel
Copy link
Author

"/Monit/ d" excludes the monitoring daemon, change to your needs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment