Add analytics script

This commit is contained in:
Konstantin Nazarov 2021-08-21 17:43:11 +01:00
parent c4403cd4e1
commit 2adacd8d19
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
2 changed files with 35 additions and 0 deletions

View file

@ -37,3 +37,6 @@ clean:
deploy:
rsync -avP --delete output/ root@knazarov.com:/var/www/knazarov.com/
analytics:
ssh root@knazarov.com "cat /var/log/nginx/access.log" | ./bin/analytics.sh

32
bin/analytics.sh Executable file
View file

@ -0,0 +1,32 @@
#!/bin/bash
#awk -v today="$TODAY" '{print today}'
present() {
grep "$TODAY" | grep GET | awk '($9 !~ /404/)' | awk '{print $7}' | sed 's/\?.*$//g' | grep -v -E "\.php|\.xml|http:" | sed 's:\(.\)/$:\1:' | sort | uniq -c | sort -rn
}
if [ "$1" == "--today" ]; then
TODAY="$(date "+%d/%b/%Y")"
shift
else
TODAY=""
fi
if [ -z "$1" ]; then
LOGFILE="/var/log/nginx/access.log"
else
LOGFILE="$1"
fi
if [ -t 0 ] && [ ! -f "$LOGFILE" ]; then
echo "Logfile doesn't exist: $LOGFILE"
exit 1
fi
if [ ! -t 0 ]; then
present
else
present < "$LOGFILE"
fi