Add analytics script
This commit is contained in:
parent
c4403cd4e1
commit
2adacd8d19
2 changed files with 35 additions and 0 deletions
3
Makefile
3
Makefile
|
@ -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
32
bin/analytics.sh
Executable 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
|
Loading…
Reference in a new issue