#! /bin/bash # script analyses ALL GUI production.log files for most visited pages # results will be in the /tmp/log_analysis . /usr/src/m2/framework/bash_functions.sh . /usr/src/m2/framework/settings.sh # ---- VARS ----- VERSION="1.1.1" SCRIPT_NAME="M2 GUI Log Analysis for Most-visited-pages" SRC_DIR="/home/m2/log" DIR="/tmp/log_analysis" LOG=$DIR/p TMP_FILE1="$DIR/p1" RESULT_FILE="$DIR/gui_most_visited_pages_result.log" # ---- MAIN ----- k_start if [ -d $DIR ];then report "$DIR present" 0 else report "$DIR not present" 2 mkdir $DIR if [ -d $DIR ];then report "$DIR created" 4 else report "Failed to create $DIR" 1 exit fi fi if [ -d $SRC_DIR ];then report "$SRC_DIR present" 0 else report "$SRC_DIR not present. No GUI on server?" 2 exit 1 fi rm -fr $TMP_FILE1 #FILES="$SRC_DIR/production.log" # one file for testing FILES="$SRC_DIR/production.log*" # all files for f in $FILES do report "Processing $f file..." 3 cp -fr $f $LOG # getting links, removing parts after ?, digits at the end of string, / at the end cat $LOG | zgrep "Started GET" | grep -v "assets" | grep -v "images" | grep -v "hourly_actions" | grep -v "paypal/payment" | cut -d\" -f2 | awk -F '?' '{print $1}' | sed 's/[0-9]\+$//' | sed 's/\/$//' >> $TMP_FILE1 done rm -fr $LOG rm -fr $RESULT_FILE report "Finished gathering data" 0 report "Calculating most visited pages..." 3 cat $TMP_FILE1 | sort | uniq -c | sort -k1nr > $RESULT_FILE report "Finished calculating" 0 report "Results in: $RESULT_FILE" 3 echo echo "Most popular pages:" echo cat $RESULT_FILE | head -30 echo rm -fr $TMP_FILE1 report "Script completed" 3