Back to the main page

Get stats of some license tool

There is some customized tool for s/w license creation and it logs an action to log, looks like:
17717 2012/11/07 15:46 username GENERATED /home/support/licenses/temp/company-123-321-linux999.txt 16748 250 250 250 0 1 1 00:15:3E:3F:46:A7 0 0
And I want to know how many licenses were created each year and who created them.

#!/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
And output is like:
% ./licensestat.sh
Available years are
2003
2004
2005
2006
2007
2008
2009
2011
Type the year(s):
2007 2009

##############################################
Year:                                     2070
Total # of created licenses:               794
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User:       # of Licenses:        Percentage:
..............................................
obrenovic           1                  .12 %
karadjordje        13                 1.63 %
jelisaveta         58                 7.30 %
janko             606                76.32 %
stanko             88                11.08 %
vuk                 4                  .50 %
milan              24                 3.02 %

##############################################
Year:                                     2009
Total # of created licenses:	           534
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User:       # of Licenses:        Percentage:
..............................................
john	           17                 3.18 %
mary	          460                86.14 %
steve	           55                10.29 %
milan	            2                  .37 %

Back to the main page