#!/bin/ksh ## ## SCRIPT NAME: get_nas_usage ## ## Where : in $FEDIR/scripts where FEDIR=/apps/nns_com/fea ## ########################################################################### ## PURPOSE: Runs an egrep-sed-awk-sort-uniq pipe on NNS MSC/NASTRAN license ## log file to extract userids, product/feature-names, ## usage date-times. ## ## Two reports are created: ## 1) a PRODUCT-USERID COUNTS SUMMARY report ## AND ## 2) a CHRONLOGICAL ACTIVITY report (optional). ## ########################################################################### ## MAINTENANCE NOTE: ## ## When a new release of NASTRAN is installed, the FLEXLOGFILE variable, ## near the top of this script, ## should be set to the new log file name. (Or, if two releases are ## available for a while, the user can be given a choice of log files.) ## ## In 1998 the MSC/NASTRAN 70 log was in /apps/msc/msc70/flexlm/lmgrd.log ## ########################################################################### ## MAINTENANCE HISTORY: ## Written by: B. Montandon 14Sep98 based on chk_varmail & alarm_netidelta_1host ## Updated by: B. Montandon 16Sep98 touched up report text & script comments ## Updated by: B. Montandon 28Oct99 Touched up report comments some more. ## ########################################################################### . $FEDIR/scripts/clearnns ########################################################################### ## LICENSE SERVER (sgia) HOST CHECK. ########################################################################### # # if test ! "sgia" = "`hostname`" # then # echo " # Login to 'sgia' !!! # # For much faster build of the list of userids # from NASTRAN FLEXlm log file. # " # exit # fi ########################################################################### ## INDICATE REPORT OPTIONS to the user -- ## and PROMPT FOR NASTRAN VERSION, if needed. ########################################################################### echo "${HIbold}\ ...................................................................... MSC(NASTRAN)_usage: ${HIreset} This utility generates 1) A PRODUCT-USERID COUNTS SUMMARY report -- of NNS MSC Product (and Feature) usage on the 'sgia' network which is followed by an optional 2) CHRONLOGICAL ACTIVITY report -- of NNS MSC Product/Feature usage. *** Press Enter to continue." read NNS_JUNK ########################################################################### ## SET INPUT & OUTPUT FILE NAMES. ########################################################################### FLEXLOGFILE="/apps/msc/msc70/flexlm/lmgrd.log" if test "$FEDIR" = "" then export FEDIR=/apps/nns_com/fea fi ###################################################### ## TIMESTAMP=`date +%Y%b%d_%T%p` ## OUTLIST="$HOME/NASTRAN_USERIDS.LIST_${TIMESTAMP}" ## rm -f $OUTLIST ###################################################### . $FEDIR/scripts/set_localoutlist ########################################################################### ## PREPARE 'PRODUCT-USERID COUNTS' SUMMARY REPORT HEADING. ########################################################################### echo "\ .................. `date` ................... MSC PRODUCT-USERID SUMMARY COUNTS (since last boot-up of license manager): from NNS NASTRAN log file $FLEXLOGFILE Note: You can browse the detail in the NNS NASTRAN FLEXlm log file at nnsFEAmenu option 'N L' (NASTRAN, Licenses-status). You can double-check these counts against the complete log file -- for example, by 'grep'-ing (finding all occurrences of) a userid. This list is prepared by a moderately complex 'awk' program (combined with 'egrep', 'sed', 'sort', & 'uniq') seen in $FEDIR/scripts/get_nas_usage This report uses the user 'IN:' (license check-out) records of the log file. The date-times of the user 'OUT:' (license check-in) records can be seen in the log file. For readability, this utility re-formats the free-format 'IN:' records into columnar-format records. Names & depts corresponding to userids can be looked up via nnsFEAmenu options 'h su 0' or 'h su 1', where 'h su' is short for 'Help, SgiaUsers'. This SORTED list was put in $OUTLIST Generated at host `hostname` by nnsFEAmenu option 'h su 21'. ========================================================================= Use MSC Count Product Userid ---- --------------------- ------ " > $OUTLIST ########################################################################### ## USE 'awk' TO PUT USER RECS IN OUTPUT FILE. ########################################################################### ## For testing: # set -x egrep 'started on|TIMESTAMP|IN:' $FLEXLOGFILE | \ sed 's|@| |g' | \ awk '{ if ( $5 ~ "started" ) { ################################################################# ### In 'started' recs: ### Field#NF (last field) =date (in parentheses) ### Sample rec: ### 11:17:41 (lmgrd) FLEXlm (v5.12) started on sgia (sgi IP19) (8/17/1998) ################################################################# # SAVDATE1 = $NF SAVDATE1 = substr($NF,2,9) continue } if ( $3 ~ "TIMESTAMP" ) { ################################################################# ### In 'TIMESTAMP' recs: ### Field#4=date ### Sample rec: ### 17:17:41 (lmgrd) TIMESTAMP 8/17/1998 ################################################################# SAVDATE2 = $4 continue } if ( $3 ~ "IN:" ) { ## For NASTRAN-feature-only info: # if ( $4 ~ "NASTRAN" ) { ################################################################# ### In 'IN:' recs: ### Field#1=Time-of-day Field#4=product Field#5=userid Field#6=hostid ### Sample rec: ### 14:09:56 (MSC) IN: "NASTRAN" edt00@iaw027 (104 licenses) ################################################################# printf (" %-23s %-8s \n", $4, $5 ) ## printf ( "this is an IN: rec \n" ) # } } } ################################################################### ### Print out date range at end of report. ### Then 'sort' the output by userid and use 'uniq' to count usage ### of each product by each userid. ################################################################### END { printf ("This is usage between %12s and %12s \n", SAVDATE1, SAVDATE2) }' | \ sort +0 -1 +1 -2 | \ uniq -c >> $OUTLIST ################################################################### ## awk OUTPUT NOTES: ## The 'awk' output recs contain only 2 fields: Product-name and userid. ## The 'sort' sorts on Product-name first, then userid. ## The 'uniq' counts occurrences of unique Product-name & userid records. ################################################################### ################################################################### ## SHOW/PRINT 'PRODUCT-USERID ACTIVITY' SUMMARY REPORT. ################################################################### $FEDIR/scripts/shofil $OUTLIST ################################################################### ## ASK IF 'CHRONOLOGICAL-ACTIVITY' REPORT IS WANTED. ################################################################### echo "${HIbold}\ .......................................................................... Do you want to see a *CHRONOLOGICAL-ACTIVITY* detail report, expanding the report you just saw in $OUTLIST?${HIreset} y ${HIbold} (y or null to exit) ==>${HIreset} \c" read REPORT_YN # if test "${REPORT_YN}" = "" if test ! "${REPORT_YN}" = "y" then # break continue # exit fi ######################################################################### ## SET OUTPUT FILENAME FOR 'CHRONOLOGICAL-ACTIVITY' REPORT. ######################################################################### OUTLIST2=${OUTLIST}2 ######################################################################### ## PREPARE 'CHRONOLOGICAL-ACTIVITY' REPORT HEADING. ######################################################################### echo "\ .................. `date` .................. NNS MSC USERID ACTIVITY (since last boot-up of the NNS license manager) -- IN ORDER BY DATE-TIME: Extracted from NNS NASTRAN log file $FLEXLOGFILE NOTE: You can browse the full detail in the NNS NASTRAN FLEXlm log file at nnsFEAmenu option 'n l' or 'N L' (NASTRAN, Licenses-status). This list is prepared by a moderately complex 'awk' program (combined with 'egrep') seen in $FEDIR/scripts/get_nas_usage This report uses the user 'IN:' (license check-out) records of the log file. The date-times of the user 'OUT:' (license check-in) records can be seen in the log file. For readability, this utility re-formats the free-format 'IN:' records into columnar-format records. Names & depts corresponding to userids can be looked up via nnsFEAmenu options 'h su 0' or 'h su 1', where 'h su' is short for 'Help, SgiaUsers'. This SORTED list was put in $OUTLIST Generated at host `hostname` by nnsFEAmenu option 'h su 21'. ========================================================================= " > $OUTLIST2 ######################################################################### ## USE 'awk' TO PUT USER RECS IN OUTPUT FILE. ######################################################################### ## For testing: # set -x egrep 'started on|TIMESTAMP|IN:' $FLEXLOGFILE | \ awk '{ if ( $5 ~ "started" ) { ############################################################# ### In 'started' recs: ### Field#NF (last field) =date (in parentheses) ############################################################# # SAVDATE = $NF SAVDATE = substr($NF,2,9) continue } if ( $3 ~ "TIMESTAMP" ) { ############################################################# ### In 'TIMESTAMP' recs: ### Field#4=date ############################################################# SAVDATE = $4 continue } if ( $3 ~ "IN:" ) { ############################################################# ### In 'IN:' recs: ### Field#1=Time-of-day Field#4=product Field#5=userid@hostid ############################################################# printf ("%12s %8s %-23s %-8s \n", SAVDATE, $1, $4, $5 ) ## printf (" %8s %12s %15s \n", $1, $4, $5 ) ## printf ( "this is an IN: rec \n" ) } }' >> $OUTLIST2 ################################################################### ## SHOW/PRINT 'CHRONOLOGICAL-ACTIVITY' REPORT. ################################################################### $FEDIR/scripts/shofil $OUTLIST2