The best way to code "htmlElementcount.sh"
In place of reading each line of the access log you should use the shell commands and egrep tool to do the hard work for you!
For performance use mixed upper and lower case searches e.g. [Hh] as this is quicker than using '-i'.
So we would code...
For performance use mixed upper and lower case searches e.g. [Hh] as this is quicker than using '-i'.
So we would code...
- Code: Select all
#!/bin/bash
#
# htmlElementcount.sh
function die {
echo "$*" >&2 ; exit 1
}
[ 1 -ne $# ] && die "usage: $(basename $0) LOG_FILE"
[ ! -e $1 ] && die "LOG_FILE [$1] does not exist"
[ ! -s $1 ] && die "LOG_FILE [$1] is empty"
cat <<EOF
Page Hits
$(wc -l < $1 | tr -d ' ') pages accessed - Form Elements Processed:
$(egrep -cq '[.][Hh][Tt][Mm][Ll]' $1| tr -d ' ') html pages accessed
$(egrep -cq '[.][Gg][Ii][Ff]' $1| tr -d ' ') GIF files accessed
$(egrep -cq '[.][Jj][Pp][Gg]' $1| tr -d ' ') jpg files accessed
EOF
exit 0