Skip to content

Instantly share code, notes, and snippets.

@olivierlemoal
Created July 1, 2014 13:23
Show Gist options
  • Save olivierlemoal/3eda4e62ce581358fb47 to your computer and use it in GitHub Desktop.
Save olivierlemoal/3eda4e62ce581358fb47 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
# Default config
declare OUTPUT_FILE="analyse.txt"
declare VERBOSE=0
declare INPUT="*.log"
# Set parameters
while getopts "vi:o:" OPTION
do
case $OPTION in
v) VERBOSE=1
;;
i) INPUT=$OPTARG
;;
o) OUTPUT_FILE=$OPTARG
;;
esac
done
declare -a dirs=("/admin/" "/tools/" "/stats/" "/host-manager/html" "/manager/html" "/cms/login");
declare -a http_codes=("200" "404" "302" "400" "401")
# Standard output in file
exec 3>&1 1>>${OUTPUT_FILE} 2>&1
echo "Analyse dans $OUTPUT_FILE" 1>&3
echo "Veuillez patienter" 1>&3
for dir in "${dirs[@]}"
do
echo "######## Analyse du chemin $dir"
declare output=$(cat $INPUT | grep " $dir")
for http in "${http_codes[@]}"
do
declare requests=$(echo "$output" | grep " $http ")
if [[ -n $requests ]]
then
echo "-HTTP $http-"
echo "Nombre de requêtes :"
declare count=$(echo "$requests"| wc -l)
echo "$count"
if [[ $count -ne 0 ]] && [[ $VERBOSE -eq 1 ]]
then
echo -en "\n"
declare IPs=$(echo "$requests"| awk '{print $1}' | sort -u)
declare URLs=$(echo "$requests"| awk '{print $6, $7}' | sort -u)
echo "IPs :"
echo "$IPs"
echo -en "\n"
echo "URLs :"
echo "$URLs"
fi
echo -en "\n"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment