All pastes #497118 Raw Edit

Anonymous

public shellscript v1 · immutable
·published 2007-05-19 17:14 UTC
rendered paste body
drawline() {	case "$1" in		[0]*)	echo "/---------------------------------------------------------------------\\" ;;		[1]*)	echo "\\---------------------------------------------------------------------/" ;;		[2]*)	echo "|                                                                     |" ;;		*)	echo "|---------------------------------------------------------------------|" ;;	esac}show() {	echo -n "|  "	echo -n "$1"	LENGTH=${#1}	SPACES=$[ 65 - $LENGTH ]	i=0	while [ $i -lt $SPACES ]	do		echo -n " "		i=$(( $i + 1 ))	done	echo "  |"}showmenu() {	clear	drawline 0	drawline 2	echo "|                            W e l c o m e                            |"	echo "|                                 T o                                 |"	echo "|                   W e b   S t a t s   H e l p e r                   |"	drawline 2	drawline	if [ "$1" = "invalid" ]	then		drawline 2		show "Invalid Option"		drawline 2 		drawline	fi	drawline 2	show "Please select a task from the menu."	show "1. Display 10 most popular webpages"	show "2. Display number of hits per hour for a webpage"	show "3. Display number of unique visitors for all pages"	show "4. Exit"	drawline 2	show "At any time type \"menu\" to return to this screen"	drawline 2	drawline 1	echo ""	echo -n "  Your selection: "	read SELECT	case "$SELECT" in		[1]*)	top10 ;;		[2]*)	hitsperhour ;;		[3]*)	uniquehits ;;		[4]*)	exit ;;		*)		showmenu "invalid" ;;	esac}top10() {	clear	drawline 0	drawline 2	echo "|                       T o p   1 0   P a g e s                       |"	drawline 2	if [ "$1" = "invalid" ]	then		drawline		drawline 2		show "Invalid Option"		drawline 2 	fi	drawline	drawline 2	show "Please enter a date."	show "Example \"Nov 11\" or \"Jul 02\""	drawline 2	drawline 1	echo ""	echo -n "  Date: "	read TOP10DATE	if [ "$TOP10DATE" = "menu" ]	then		showmenu	else		case "$TOP10DATE" in			[A-Za-z][A-Za-z][A-Za-z]?[0-9][0-9])				for i in $( ls hits )				do					HITS=$( grep "$TOP10DATE" hits/$i | wc -l )					echo "  $HITS	|  $i" >>top10				done				clear				echo "Top 10 Most Popular Pages for $TOP10DATE"				echo "----------------------------------------"				echo ""				echo "	  Hits	|  Page"				sort -gr top10 | head -n 10 | cat -n				rm top10				echo ""				drawline 0				drawline 2				show "Type anything to return to the menu."				drawline 2				drawline 1				echo ""				echo -n "  Your selection: "				read RETURN				case "$RETURN" in					*)	showmenu ;;				esac ;;			*)	top10 "invalid" ;;		esac	fi}hitsperhour() {	clear	drawline 0	drawline 2	echo "|                      H i t s   p e r   H o u r                      |"	drawline 2	if [ "$1" = "invalid" ]	then		drawline		drawline 2		show "Invalid Option"		drawline 2 	fi	if [ "$1" = "fileerror" ]	then 		drawline		drawline 2		show "That file does not exist"		drawline 2 	fi	drawline	drawline 2	show "Please enter a date."	show "Example \"Nov 11\" or \"Jul 02\""	drawline 2	drawline 1	echo ""	echo -n "  Date: "	read DATE	if [ "$DATE" = "menu" ]	then		showmenu	else		case "$DATE" in			[A-Za-z][A-Za-z][A-Za-z]?[0-9][0-9])				clear				drawline 0				drawline 2				for i in $( ls hits )				do					show "$i $COUNT"				done				drawline 2				drawline				drawline 2				show "Your selected date is $DATE"				drawline 2				show "Please enter the name of the file from the list above."				show "Example \"index.hits\" or \"contact.hits\""				drawline 2				drawline 1				echo ""				echo -n "  File: "				read PAGE				if [ "$PAGE" = "menu" ]				then					showmenu				else					case "$PAGE" in						[a-z]*)							if [ -r "hits/$PAGE" ]							then								clear								i=0								while [ $i -le 23 ]								do									if [ $i -le 9 ]									then										TIME=$( "0$i" )									else										TIME="$i"									fi									HITS=$( grep "$DATE $TIME" hits/$PAGE | wc -l )									echo "  $i  	|  $HITS" >>hitsperhour									i=$(( $i + 1 ))								done								echo "Hits Per Hour For $PAGE On $DATE"								echo "----------------------------------------"								echo ""								echo "  Hour	|  Hits"								head -n 24 hitsperhour								echo ""								drawline 0								drawline 2								show "Type anything to return to the menu."								drawline 2								drawline 1								echo ""								echo -n "  Your selection: "								read RETURN								case "$RETURN" in									*)	showmenu ;;								esac							else								hitsperhour "fileerror"							fi ;;						*) hitsperhour "invalid" ;;					esac				fi ;;			*)	hitsperhour "invalid" ;;		esac			fi}uniquehits() {	clear	drawline 0	drawline 2	echo "|                        U n i q u e   h i t s                        |"	drawline 2 	drawline 1	echo ""	echo "Unique hits across all pages of all time"	echo "----------------------------------------"	echo ""	echo "  Hits	|  Page"	for i in $( ls hits )	do		HITS=$( awk '{ print $1 }' hits/$i | sort | uniq | wc -l )		echo "  $HITS	|  $i"	done	echo ""	drawline 0	drawline 2	show "Type anything to return to the menu."	drawline 2	drawline 1	echo ""	echo -n "  Your selection: "	read RETURN	case "$RETURN" in		*)	showmenu ;;	esac}showmenu