-- Leo's gemini proxy
-- Connecting to m0yng.uk:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini;lang=en
Created 2021-06-10
Modified 2021-07-13
Linux
'cos I can't document this in just one toot...
#!/bin/bash # Tell the server hostname and today's date echo "Visitors to $(hostname) on $(date +%d/%b/%Y)" # Search nginx log file for today's date and slice it up to get just IP addresses, then sort them, then get just the unique ones, then count them HTTPV=$(grep "\[`date +%d/%b/%Y`" /var/log/nginx/access.log | cut -d" " -f1 | sort | uniq | wc -l) # same for gopher GOPHERV=$(grep "\[`date +%d/%b/%Y`" /var/log/gopher | cut -d" " -f1 | sort | uniq | wc -l) # same for gemini GEMINIV=$(grep "`date +'%b %d'`" /var/log/gemini.log | cut -d" " -f11 | sort | uniq | wc -l) # Tell the counts echo "HTTP Gopher Gemini" echo "$HTTPV $GOPHERV $GEMINIV"
Gives an output like this
Visitors to server.m0yng.uk on 10/Jun/2021 HTTP Gopher Gemini 43 2 6
A slightly more advanced version, this tries to get the data for yesterday too (although consistently fails for me with nginx probably due to logrotate), looks for stuff that says it is a bot, and tabulates the output for consistent output.
#!/bin/bash # Tell the server hostname and today's date echo "Visitors to $(hostname) on $(date +%d/%b/%Y)" # Search nginx log file for today's date and slice it up to get just IP addresses, then sort them, then get just the unique ones, then count them HTTPV=$(grep "\[`date +%d/%b/%Y`" /var/log/nginx/access.log | cut -d" " -f1 | sort | uniq | wc -l) # What about yesterday? HTTPY=$(grep "\[`date --date='yesterday' +%d/%b/%Y`" /var/log/nginx/access.log | cut -d" " -f1 | sort | uniq | wc -l) # Count bots and crawlers HTTPVBOT=$(grep "\[`date +%d/%b/%Y`" /var/log/nginx/access.log | grep -iE 'bot|crawler' | cut -d" " -f1 | sort | uniq | wc -l) HTTPYBOT=$(grep "\[`date --date='yesterday' +%d/%b/%Y`" /var/log/nginx/access.log | grep -iE 'bot|crawler' | cut -d" " -f1 | sort | uniq | wc -l) # same for gopher (but not the bots, are there bots on gopher?) GOPHERV=$(grep "\[`date +%d/%b/%Y`" /var/log/gopher | cut -d" " -f1 | sort | uniq | wc -l) GOPHERY=$(grep "\[`date --date='yesterday' +%d/%b/%Y`" /var/log/gopher | cut -d" " -f1 | sort | uniq | wc -l) # same for gemini GEMINIV=$(grep "`date +'%b %d'`" /var/log/gemini.log | cut -d" " -f11 | sort | uniq | wc -l) GEMINIY=$(grep "`date --date='yesterday' +'%b %d'`" /var/log/gemini.log | cut -d" " -f11 | sort | uniq | wc -l) GEMINIVBOT=$(grep "`date +'%b %d'`" /var/log/gemini.log | grep -iE 'bot|crawler' | cut -d" " -f11 | sort | uniq | wc -l) GEMINIYBOT=$(grep "`date --date='yesterday' +'%b %d'`" /var/log/gemini.log | grep -iE 'bot|crawler' | cut -d" " -f11 | sort | uniq | wc -l) # Tell the counts echo -e "\e[1;33m" # make it yellow printf "%-7s%-7s%-7s%-7s%-7s\n" "HTTP" "Bot?" "Gopher" "Gemini" "Bot?" # %-7s = left aligned 7 characters wide string. echo -e "\e[0m-----------------------------------" # stop being yellow printf "%-7s%-7s%-7s%-7s%-7s\n" $HTTPV $HTTPVBOT $GOPHERV $GEMINIV $GEMINIVBOT printf "%-7s%-7s%-7s%-7s%-7s%-9s\n" $HTTPY $HTTPYBOT $GOPHERY $GEMINIY $GEMINIYBOT "Yesterday" exit
Gives an output like this
Visitors to server.m0yng.uk on 13/Jul/2021 HTTP Bot? Gopher Gemini Bot? ----------------------------------- 585 498 0 9 0 0 0 0 18 0 Yesterday
-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-
๐ค Black Lives Matter
๐๐ค๐ Trans Rights are Human Rights
โค๏ธ๐งก๐๐๐๐ Love is Love
Copyright ยฉ 2024 Christopher M0YNG - It is forbidden to use any part of this site for crypto/NFT/AI related projects.
Page generated 2024-03-24 by Complex 19
-- Response ended
-- Page fetched on Sat May 18 21:23:23 2024