Apache serverio log failo analizė

#!/bin/shDIALOG=${DIALOG=dialog}

declare bytes_in_gb=1048576declare procentai=100

laikinas=TMPlaikinas2=TMP2

declare -a linesdeclare -a bytesamount

processLine(){ line=”$@” }

if [ “$1” == “” ]; then $DIALOG –title “DUOMENU NUSKAITYMAS” –inputbox “Iveskite log failo pavadinima:” 18 45 2> /tmp/inputbox.tmp.$$ retval=$? input=`cat /tmp/inputbox.tmp.$$` rm -f /tmp/inputbox.tmp.$$

case $retval in 0) echo “Input string is ‘$input'”;; 1) echo “Cancel pressed.”;; 255) echo “Box closed.”;; esac inputfile=”$input”

if [ ! -f $inputfile ]; then $DIALOG –title “ERRROR” –msgbox “$inputfile : neegzistuoja” > “/dev/stderr” 10 40 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac exit 1 elif [ ! -r $inputfile ]; then $DIALOG –title “ERRROR” –msgbox “$inputfile: neimanoma nuskaityti” > “/dev/stderr” 10 40 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac exit 2 fi

elif [ “$1” == “–help” ]; then $DIALOG –title “HELP” –msgbox “Programos paleidimas:n sh n.shn sh n.sh logn n n n n … created By Nerijus Kliauba ” 15 50 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac exit else inputfile=$1 if [ ! -f $inputfile ]; then $DIALOG –title “ERRROR” –msgbox “$inputfile : neegzistuoja” > “/dev/stderr” 10 40 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac exit 1 elif [ ! -r $inputfile ]; then $DIALOG –title “ERRROR” –msgbox “$inputfile: neimanoma nuskaityti” > “/dev/stderr” 10 40 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac exit 2 fifi#————————————————————————–

d=0until [ $d = 1 ];do

$DIALOG –clear –radiolist “MENIU” 15 90 8 “1” “Narsykliu statistika” off “2” “OS daznumas procentais ” off “3” “Operacines sistemos” off “4” “Kiek duomenu persiunte serveris” off “5” “Kokius metodus naudojo kiekvienas IP” off “6” “Kiekvieno lankytojo persiustas kiekis duomenu” off “7” “Suvestine” off “8” “Iseiti” off 2>/tmp/tmp.$$ input=`cat /tmp/tmp.$$`

case $input in#—————————————————————————————————- 1) rezultfile=”IE” rezultfile2=”IEPROC” echo “”>$rezultfile echo “”>$rezultfile2 echo “”>$laikinas

zcat $inputfile | grep “Mozilla/4.0” | grep “(compatible;” |grep “MSIE” | cut -f14,15 -d ” ” | sort | uniq -c | sort -g -r>>$laikinas zcat $inputfile | grep “Mozilla/5.0” | grep “Firefox” | cut -f21 -d ” “| sort | uniq -c | sort -g -r>>$laikinas zcat $inputfile | grep “Opera”| grep “Mozilla”| cut -f20,21,21,22 -d ” ” | sort | uniq -c | sort -g -r>>$laikinas

zcat $inputfile | grep “Opera”| cut -f12 -d ” “| sort | uniq -c | sort -g -r >>$laikinas zcat $inputfile | grep “Mozilla/5.0” | grep “Firefox” | cut -f20 -d ” ” | sort | uniq -c | sort -g -r>>$laikinas zcat $inputfile | grep “Mozilla/5.0” | grep “Firefox” | cut -f19 -d ” ” | sort | uniq -c | sort -g -r>>$laikinas

all=0 all=$(zcat $inputfile | wc -l) let all=all-2 echo “Viso: $all prisijungimai”>>$rezultfile echo >>$rezultfile

cat $laikinas |grep “MSIE” |grep ” 2 (compatible; MSIE” -v | cut -f1 -d ” ” >>$rezultfile2 cat $laikinas |grep “Firefox” | cut -f1 -d ” ” >>$rezultfile2 cat $laikinas |grep “Opera” | cut -f1 -d ” ” >>$rezultfile2 echo ” $(zcat $inputfile | grep “Opera” -v | grep “Firefox” -v | grep “MSIE” -v| wc -l) Other” >>$rezultfile2 echo “Narsykliu statistika: ” >>$rezultfile echo “————————–” >>$rezultfile cat $rezultfile2 |sed ‘/”/s///g’>> $rezultfile

echo “”>$rezultfile2 echo “Viso: $all prisijungimai”>>$rezultfile2 echo >>$rezultfile2 echo “Narsykle | Daznumas procentais ” >>$rezultfile2 echo “—————————————–” >>$rezultfile2 echo -n ” MSIE | “>>$rezultfile2 echo “$(($(zcat $inputfile | grep “MSIE” | wc -l)*100))/$all” |bc -l >>$rezultfile2 echo -n ” OPERA | “>>$rezultfile2 echo “$(($(zcat $inputfile | grep “Opera” | wc -l)*100))/$all” |bc -l >>$rezultfile2 echo -n ” FIREFOX | “>>$rezultfile2 echo “$(($(zcat $inputfile | grep “Firefox” | wc -l)*100))/$all” |bc -l >>$rezultfile2 echo -n ” Other | “>>$rezultfile2 echo “$(($(zcat $inputfile | grep “MSIE” -v | grep “Opera” -v | grep “Firefox” -v | wc -l)*100))/$all” |bc -l >>$rezultfile2 echo -n “—————————————–” >>$rezultfile2

rm $laikinas $DIALOG –title “RESULTS:” –msgbox “nRezultatus rasite failuose: n$rezultfilen$rezultfile2” 10 50 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac;; #———————————————————————————————– 2) rezultfile=”OSPROC” echo “”>$rezultfile all=0 all=$(zcat $inputfile | wc -l) let all=all-2 echo “Viso: $all prisijungimai”>>$rezultfile echo >>$rezultfile echo “Operacine sistema | Daznumas procentais ” >>$rezultfile

echo “—————————————–” >>$rezultfile echo -n ” Windows | “>>$rezultfile echo “$(($(zcat $inputfile | grep “Windows” | wc -l)*100))/$all” |bc -l >>$rezultfile echo -n ” Linux | “>>$rezultfile echo “$(($(zcat $inputfile | grep “Linux” | wc -l)*100))/$all” |bc -l >>$rezultfile echo -n ” Mac OS | “>>$rezultfile echo “$(($(zcat $inputfile | grep “Mac OS” | wc -l)*100))/$all” |bc -l >>$rezultfile echo -n ” FreeBSD | “>>$rezultfile echo “$(($(zcat $inputfile | grep “FreeBSD” | wc -l)*100))/$all” |bc -l >>$rezultfile echo -n ” Other | “>>$rezultfile echo “$(($(zcat $inputfile | grep “Windows” -v | grep “Linux” -v | grep “Mac OS” -v | grep “FreeBSD” -v | wc -l)*100))/$all” |bc -l >>$rezultfile echo -n “—————————————–” >>$rezultfile $DIALOG –title “RESULTS:” –msgbox “n Rezultatus rasite faile: $rezultfile” 10 50 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac;;#—————————————————————————————————— 3) rezultfile=”OS” echo “”>$rezultfile all=0 all=$(zcat $inputfile | wc -l) let all=all-2 echo “Viso: $all prisijungimai”>>$rezultfile echo >>$rezultfile echo ” Operaciniu sistemu statistika:” >>$rezultfile echo ” ——————————” >>$rezultfile echo ” Windows: $(zcat $inputfile | grep “Windows” | wc -l)” >>$rezultfile echo ” Linux: $(zcat $inputfile | grep “Linux” | wc -l)” >>$rezultfile echo ” Mac_OS: $(zcat $inputfile | grep “Mac OS” | wc -l)” >>$rezultfile echo ” FreeBSD: $(zcat $inputfile | grep “FreeBSD” | wc -l)” >>$rezultfile echo ” Other: $(zcat $inputfile | grep “Windows” -v | grep “Linux” -v | grep “Mac OS” -v | grep “FreeBSD” -v | wc -l)” >>$rezultfile echo ” ——————————” >>$rezultfile $DIALOG –title “RESULTS:” –msgbox “n Rezultatus rasite faile: $rezultfile” 10 50 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac;;#——————————————————————————————- 4)rezultfile=”SERVTRANSFER” echo “”>$laikinas echo “”>$rezultfile

zcat $inputfile | cut -f10 -d ” ” >>$laikinas bytesamount=(`cat “$laikinas”`) n=${#bytesamount[*]} index=0 bytes=0

while [ $index -lt $n ]; do if [[ ${bytesamount[$index]} != “-” ]]; then let bytes=bytes+${bytesamount[$index]} fi let index=index+1

done

if [ $bytes -gt $bytes_in_gb ] ; then echo “Buvo persiusta: $bytes baitu($(($bytes / $bytes_in_gb ))GB)” >>$rezultfile elif [ $bytes -gt 1024 ] ; then echo “Buvo persiusta: $bytes baitu($(($bytes / 1024))MB”>>$rezultfile else echo “Buvo persiusta: $bytes baitu”>>$rezultfile fi rm $laikinas $DIALOG –title “RESULTS:” –msgbox “n Rezultatus rasite faile: $rezultfile” 10 50 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac;;#—————————————————————————————- 5) rezultfile=”IPMETOD” echo “” >$rezultfile echo “Kliento IP | Metdodas naudotas” >>$rezultfile echo “——————————” >>$rezultfile echo “” >>$rezultfile zcat $inputfile | cut -f1,6 -d ” ” | sort | uniq >>$rezultfile $DIALOG –title “RESULTS:” –msgbox “n Rezultatus rasite faile: $rezultfile.” 10 50 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac;;#———————————————————————————————— 8) $DIALOG –title “EXIT” –msgbox “PROGRAM CLOSED” 10 40 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac d=1;;#————————————————————————————————– 7) rezultfile=”RESIUME” echo “”>$rezultfile echo “Rezultatai analizuojant log’o faila ‘$inputfile’:” >>$rezultfile echo >>$rezultfile echo “Pradzia: “$(zcat $inputfile |head -2 | awk ‘{print $4}’ | sed ‘s/[//’| sed ‘s/:/ at /’) >>$rezultfile echo “Pabaiga: “$(zcat $inputfile |tail -2 | awk ‘{print $4}’ | sed ‘s/[//’| sed ‘s/:/ at /’) >>$rezultfile echo >>$rezultfile ac=0 ac=$(zcat $inputfile | wc -l) let ac=ac-2 echo “Per si laika buvo: $ac prisijungimai”>>$rezultfile echo >>$rezultfile echo “Dazniausiai perziureti puslapiai: “>>$rezultfile echo “———————————–“>>$rezultfile zcat $inputfile |awk ‘{print $7}’ | sort | uniq -c | sort -rn | grep “.html” | head >>$rezultfile echo >>$rezultfile echo “Labiausiai dominusieji failai: “>>$rezultfile echo “————————————“>>$rezultfile zcat $inputfile |awk ‘{print $7}’ | sort | uniq -c | sort -rn | head >>$rezultfile $DIALOG –title “RESULTS:” –msgbox “n Rezultatus rasite faile: $rezultfile” 10 50 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac;;#———————————————————————————————————– 6) rezultfile=”IPTRANSFER” pass=0 echo “”>$rezultfile echo “”>$laikinas echo “”>$laikinas2 zcat $inputfile | cut -f1 -d ” ” |sort | uniq >>$laikinas#—————— exec 3<&0

exec 0<$laikinas

$DIALOG –title “DEMESIO” –backtitle “Nerijus Kliauba” –infobox “Prasome palaukti, programa vykdo Jusu uzklausa…..” 7 50 ; read

while read line do echo “”>$laikinas2 processLine $line zcat $inputfile | grep “$line” | cut -f10 -d ” “>>$laikinas2 bytesamount=(`cat “$laikinas2″`) n=${#bytesamount[*]} index=0 bytes=0

while [ $index -lt $n ]; do if [[ ${bytesamount[$index]} != “-” ]]; then let bytes=bytes+${bytesamount[$index]} fi let index=index+1 done

if [ $pass = 0 ] ; then echo “Kliento IP | Parsisutu duomenu kiekis” >>$rezultfile echo “———————————————” >>$rezultfile pass=1 fi

if [ $bytes -gt $bytes_in_gb ] ; then echo “$line | $bytes baitai(-u) ($(($bytes / $bytes_in_gb ))GB)” >>$rezultfile elif [ $bytes -gt 1024 ] ; then echo “$line | $bytes baitai(-u) ($(($bytes / 1024))MB)”>>$rezultfile else echo “$line | $bytes baitai(-u)”>>$rezultfile fi #———————– done exec 0<&3 rm $laikinas rm $laikinas2 $DIALOG –title “RESULTS:” –msgbox “n Rezultatus rasite faile: $rezultfile” 10 50 case $? in 0) echo “OK”;; 255) echo “Box closed.”;; esac;;

esac

done