Snippets

Dr Wolf parse apache access log filtering specific ip and http outcome

Created by Lorenzo Riganella
#!/bin/bash

# This script is used parse apache access log filtering specific ip and http outcome
#

httpStatusDelimiter=" ";

stringOld='
    ';
ipsSeparator="\|"



read -p "Which log file do you want to parse? " file2parse

if [ -z "$file2parse" ]
then
  echo "Nothing to do.";
else
  if [ ! -f "$file2parse" ]; then
        echo "File not found!";
      else
        echo "Parsing file: $file2parse";
        read -p "Which HTTP status search? " httpStatus;
        while ! [[ "$httpStatus" -gt 1 ]]; do
        
          read -p "Sorry integers only, please retype HTTP status:" httpStatus
        done

        echo "Please insert ip list (only one ip in a single line)";
        
        while read -r line && [[ -n "$line" ]]; do
          ips="$ips""$ipsSeparator""$line";
        done

        if [[ -n $ips ]]; then
          ips=${ips:2};
        fi

        httpStatus="${httpStatusDelimiter}$httpStatus${httpStatusDelimiter}";
        grep "$ips" "$file2parse" |grep -F "$httpStatus";
        
  fi
fi

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.