BASH   165
This script builds report in form of Hits CountryCode
Guest on 28th November 2024 07:05:43 AM


  1. #!/bin/bash
  2.  
  3. #
  4. # This script builds report in form of "Hits CountryCode"
  5. # Usage: bycc <nginx log>
  6. #
  7.  
  8. #set -x
  9.  
  10. EXCLUDE="(104.245.101.69|31.220.15.193|195.191.214.202)"
  11.  
  12. debot < $1 | egrep -v $EXCLUDE > 1.log
  13. cut -d' ' -f 1 1.log | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq -c | sed -e "s/^\s*//" -e "s/ /,/"  | sort -nr > ips.txt
  14. rm -f hitsbyip.txt
  15. for i in `cat ips.txt `; do
  16.    hits=`echo $i | cut -d',' -f 1`
  17.    ip=`echo $i | cut -d',' -f 2`
  18.    cc=`geoiplookup $ip | grep Country | cut -d' ' -f 4 | tr -d ','`;
  19.    echo $hits $cc $ip >> hitsbyip.txt
  20. done
  21. cut -d' ' -f 2 hitsbyip.txt | sort | uniq > ccs.txt
  22. for i in `cat ccs.txt `; do
  23.    hits=0;
  24.    for j in `grep " $i " hitsbyip.txt | cut -d' ' -f 1`; do hits=$(($hits+$j)); done
  25.    echo $hits $i;
  26. done | sort -n -r > hitsbycc.txt
  27. rm -f 1.log
  28. cat hitsbycc.txt

Raw Paste

Login or Register to edit or fork this paste. It's free.