Skip to content

Instantly share code, notes, and snippets.

@mrjones-plip
Created October 16, 2023 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrjones-plip/27c23e307183aee642690df79a4ed9d3 to your computer and use it in GitHub Desktop.
Save mrjones-plip/27c23e307183aee642690df79a4ed9d3 to your computer and use it in GitHub Desktop.
generate.stats.sh
#!/bin/bash
set -u
echo "erasing results.txt"
cat /dev/null > results.txt
if [ ! -f cache/responses.3.log ]; then
echo "caching 3.x responses"
grep medicmobile.org CHT3/*log|cut -f7,8,9 -d " " |grep -v "^\-1"|cut -f3 -d " " \
| sort|uniq -c|sort -rn|tr -s " "|awk ' { t = $1; $1 = $2; $2 = t; print; } ' \
| sort > cache/responses.3.log
fi
if [ ! -f cache/responses.4.log ]; then
echo "caching 4.x responses"
grep medicmobile.org CHT4/*log|cut -f7,8,9 -d " " |grep -v "^\-1"|cut -f3 -d " " \
| sort|uniq -c|sort -rn|tr -s " "|awk ' { t = $1; $1 = $2; $2 = t; print; } ' \
| sort > cache/responses.4.log
fi
echo "CODE 3.x 4.x" >> results.txt
echo "--------------------"
join -t" " -a1 cache/responses.3.log cache/responses.4.log | column -t -c 3|sed 's/[[:blank:]]\+/\t/g' >> results.txt
stats() {
if [ ! -f cache/$1-502cache ]; then
echo "caching 502 results in cache/$1-502cache"
grep -P "\d{2} -1 502 " $1/*.log|grep "medicmobile.org" >cache/$1-502cache
fi
if [ ! -f cache/$1-domaincache ]; then
echo "caching domain list in cache/$1-domaincache"
cut -f14 -d " " $1/*.log|cut -f2 -d":"|grep "medicmobile.org"|sort|uniq>cache/$1-domaincache
fi
echo >> results.txt
echo "----- $1 -----">> results.txt
echo "502s Total Domain">> results.txt
echo "----------------">> results.txt
for domain in `cat cache/$1-domaincache`
do
echo "calcuilating stats for $domain..."
counter=`grep "$domain" cache/$1-502cache | cut -f9 -d " " |grep "502"|wc -l`
gross=`grep -o "$domain" $1/*.log| wc -l`
echo "$counter $gross $domain"|sed -e 's/\/\///g'|sed 's/[[:blank:]]\+/\t/g'>> results.txt
done
}
stats CHT4
stats CHT3
echo "Done! See results.txt for results"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment