Created
February 15, 2024 08:34
-
-
Save maikschneider/74e6625f2eacbe2a43f3399def0b82fb to your computer and use it in GitHub Desktop.
Create daily GoAccess reports
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 | |
LOG_FILES="/var/log/apache2/access_domain.de.log*" | |
TARGET_DIR="/var/www/html/goaccess/daily" | |
mkdir -p $TARGET_DIR | |
rm -f $TARGET_DIR/* | |
# Split log files per date | |
for FILE in $LOG_FILES; do | |
awk '{print $4}' "$FILE" | cut -d '[' -f2 | cut -d ':' -f1-2 | sort | uniq | | |
while read -r date | |
do | |
FORMATTED_DATE=$(echo "$date" | awk -F'/' '{split($2, month, "/"); printf "%s-%s-%s", $1, month[1], $3}') | |
FORMATTED_DATE=${FORMATTED_DATE%???} | |
grep "$date" "$FILE" >> "$TARGET_DIR/access_log_$FORMATTED_DATE.txt" | |
done | |
done | |
# run goaccess | |
DIR="$TARGET_DIR/access_log_*.txt" | |
for FILE in $DIR; do | |
JSON_FILE="${FILE%????}.json" | |
goaccess $FILE -a -o "$JSON_FILE" --no-ip-validation --log-format=COMBINED --ignore-crawlers | |
rm $FILE | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment