Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment 6.pdf Tools Assignment 6.pdf x 70.6% Assignment 6 This assignment is

ID: 3574545 • Letter: A

Question

Assignment 6.pdf Tools Assignment 6.pdf x 70.6% Assignment 6 This assignment is due at 11:30 PM on Monday December 12th. This is the Monday right before the final exam. You can do this assignment using loki.ist.unomaha.edu and using your UNO netid and password to log in. Your assignment is to write a shell script named "astats.sh". You may also need to write a few additional small chunks of code in Awk or Perl or something as well. The script reports and prints selected information gleaned from the Apache web server logs. Again, I will describe the action ofthis shell script by first showing the help information: Usage ./astats.sh

Explanation / Answer

export logfile=apache.log

datefmt="%d/%b/%Y"

getFileLines()

{

export current_date=$1

export thatDate=$2

extractOption=$3

cut -d" " -f4 ${logfile}|cut -d"[" -f2|cut -d":" -f1| awk ' { if ($0 <= ENVIRON["current_date"] && $0 >= ENVIRON["thatDate"]) print $0; } ' > list

actualsize=$(wc -l < list)

if [ $actualsize == 0 ];

then

printf "No matching data exists !!! "

exit 0;

else

case "$extractOption" in

"IPS")

grep -f list ${logfile} | cut -d" " -f1|uniq -c

;;

"USERS")

grep -f list ${logfile} |cut -d" " -f6-7|uniq

;;

esac

fi

}

current_date=`date +"${datefmt}"`

case "$2" in

"week")

thatDate=`date -v -7d +"${datefmt}"`

getFileLines $current_date $thatDate $1

;;

"month")

thatDate=`date -v -1m +"${datefmt}"`

getFileLines $current_date $thatDate $1

;;

"day")

thatDate=`date -v -1d +"${datefmt}"`

getFileLines $current_date $thatDate $1

;;

*)

thatDate=`date -v $2d +"${datefmt}"`

getFileLines $current_date $thatDate $1

;;

esac