Get the top 10 IPs from all the log files (Bash)

Extract tar.gz and acess all the log files and find the top 5 IP addresses with status 5xx and excluding

#!/usr/bin/env bash
rm &>/dev/null
rm &>/dev/null
rm /tmp/report.log &>/dev/null
tar xvf archive.tar.gz
for logfile in $(find .  -name *.log); do
    # echo $logfile
    grep -o "5.. [0-9]+.[0-9]+.[0-9]+.[0-9]+"  $logfile| grep -v "" >>
grep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+" | sort | uniq -c | sort -nr >
for i in $(seq 10); do
       read line
       echo $line >> /tmp/report.log
done <
rm *.log
exit 0

Leave a Reply