#!/bin/sh
#set -x
# variables
AWK=/usr/local/bin/gawk
LOGFILE=/some_path/license.log
# list available years
AVAIL_YEARS=`cat ${LOGFILE} | ${AWK} '{print $2}' | ${AWK} -F"/" '{print $1}' | sort | uniq`
printf "Available years are \n${AVAIL_YEARS}\nType the year(s):\n"
# get user's input
read YEARS
for j in ${YEARS}
do
printf "\n\n############################################## \n"
printf "%-35s %10s \n" "Year:" "${j}"
# Total Number of Licenses in Year
TNLY=`cat ${LOGFILE} | ${AWK} '$2 ~ /'${j}'\/[0-9]+\/[0-9]+/ {print $0}' | wc -l`
printf "%-35s %10s \n" "Total # of created licenses:" "${TNLY}"
printf "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- \n"
# users who created licenses in this year
USERSYEAR=`cat ${LOGFILE} | ${AWK} '$2 ~ /'${j}'\/[0-9]+\/[0-9]+/ {print $4}' | sort | uniq`
printf "%-10s %15s %18s \n" "User:" "# of Licenses:" "Percentage:"
printf ".............................................. \n"
for u in ${USERSYEAR}
do
# below line prints all licenses created by user
#cat ${LOGFILE} | ${AWK} '$2 ~ /'${j}'\/[0-9]+\/[0-9]+/ && $4 ~ /'${u}'/ {print $0}'
# Number of Licenses User created in this year
NLU=`cat ${LOGFILE} | ${AWK} '$2 ~ /'${j}'\/[0-9]+\/[0-9]+/ && $4 ~ /'${u}'/ {print $0}' | wc -l`
# Percentage of Number of Licenses User created in this year
# scale=2 means: float number with 2 decimal digits
PNLU=`(echo "scale=2; ${NLU}*100/${TNLY}" | bc -l)`
# Below works on Solaris, but not on Linux Red Hat
#PNLU=`bc -l << E
#scale=2
#${NLU}*100/${TNLY}
#E`
printf "%-10s %10s %22s\n" "${u}" "${NLU}" "${PNLU} %"
done
done
exit 0
|