Hello, wondering if anybody may be help me. This is the output of a file, from which I need to display a number of fields regarding which users are using licences for two applications we run. Lines which end with "(linger: 1800)" denote licence use for one application and lines which don't contain this denote licence use of the other.
I need to be display fields $4, $8, $9, $11 and $12, which I have been able to do. The problem I have though, is that in my output, I need to be able to substitute "(linger: 1800)" with "ChangeBase" and for lines which don't contain "(linger: 1800)" I want to display "CMBase".
In addition to that, I need to read field $4 (user ID) of each line and perform a ypmatch command against it, so I can display the name of the user at the end of each line.
If anybody has any suggestions or pointers, it would be much appreciated.
UserID Process ID Time Active Licence Type User Name
------ ---------- ----------- ------------ ---------
z310084 1079 start Fri 11:43 ChangeBase J Bloggs
z004021 1618 start Fri 11:53 ChangeBase A Bloggs
ChangeAdmin 2155 start Fri 5:30 ChangeBase
z001698 1994 start Fri 12:02 ChangeBase C Bloggs
z600969 1885 start Fri 9:21 CMBase D Bloggs
oracled 2083 start Fri 10:51 CMBase Oracle DBA
z001698 2380 start Fri 10:55 CMBase F Bloggs
z311361 1393 start Fri 11:29 CMBase G Bloggs
u414014 580 start Fri 7:58 CMBase H Bloggs
z310086 1409 start Fri 11:44 CMBase I Bloggs
Users of SYNERGY-ChangeBase: (Total of 11 licenses issued; Total of 4 licences in use)
Users of SYNERGY-CMBase: (Total of 12 licenses issued; Total of 6 licences in use)
I already have a shell script and a couple of awk scripts which worked fine and displayed all of the above with the exception of "User Name".
These scripts as follows:
Script cmsynergy_licence_admin.sh
LICENCEFILE=$HOME/cmsynergy_licences
LICENCE_COUNT_OUTPUT=$HOME/output_of_cmsynergy_licences
FORMATTED_LICENCE_COUNT=$HOME/formatted_licence_count
view_licences()
{
clear
ccm set role ccm_admin
LINENUM=1
/agsdev/continuus/flexnet/lmutil lmstat -a -c /agsdev/continuus/flexnet/license.dat > $LICENCEFILE
nawk -f /agsdev/continuus/ccm_root/bin/cmsynergy_count_licences.awk $LICENCEFILE > $LICENCE_COUNT_OUTPUT
sed 's/$/ CMBase/' $LICENCE_COUNT_OUTPUT > $FORMATTED_LICENCE_COUNT
nawk -F" " -f /agsdev/continuus/ccm_root/bin/cmsynergy_display_licences.awk $FORMATTED_LICENCE_COUNT
INC_BY=`nawk -F" " -f /agsdev/continuus/ccm_root/bin/cmsynergy_display_licences.awk $FORMATTED_LICENCE_COUNT | wc -l`
delete_temp_files
LINENUM=`echo "$LINENUM + $INC_BY -1" | bc`
print_line 1 "View username holding a licence...............[1]"
print_line 1 "Terminate a SYNERGY-CMBase licence............[2]"
print_line 1 "Return to Main Menu...........................[9]"
print_line 1 "Select an option [ ]"
tput cup $LINENUM 19
read V_OPTION
if [ -z "$V_OPTION" ]
then
V_OPTION=0
fi
case "$V_OPTION" in
'1')
print_line 1
print_line 1 "Enter the User ID: "
read USERNAME
print_line 1
ypmatch $USERNAME passwd | nawk -F: '{ print $5 }'
print_line 1
print_line 1 $BOLD_ON"Press return to continue..."$BOLD_OFF
read x
view_licences
;;
'2')
kill_process
;;
'9')
main_menu
;;
*)
view_licences
;;
esac
}
kill_process()
{
print_line 1 "Enter the Process ID of the SYNERGY-CMBase licence you wish to terminate: "
read PID
ask_yesno "ARE YOU SURE? y/n [ ]"
if [ $? -eq 0 ]
then
clear
LINENUM=1
/agsdev/continuus/flexnet/lmutil lmremove -c /agsdev/continuus/flexnet/license.dat -h SYNERGY-CMBase Phys-agsdev 19353 $PID
print_line 1
print_line 1 "Terminating licence associated with $PID..."
sleep 1
# print_line 1 $BOLD_ON"Press return to continue..."$BOLD_OFF
# read x
view_licences
else
echo
echo "Cancelling the termination of Process ID $PID..."
sleep 1
view_licences
fi
view_licences
}
delete_temp_files()
{
rm $LICENCEFILE
rm $LICENCE_COUNT_OUTPUT
rm $FORMATTED_LICENCE_COUNT
Script cmsynergy_display_licences.awk
BEGIN {
print ""
print "User Process ID Time Active Licence Type"
print "---- ---------- ----------- ------------"
}
NF > 12{changebaselicences++}
NF < 13{cmbaselicences++}
{
gsub(/\(/, " ", $0)
gsub(/\)/, " ", $0)
gsub(","," ", $0)
gsub("linger: 1800","ChangeBase", $0)
print $4, " ", " ", $7, " ", " ", $8, $9, $11, " ", $12
}
END {
printf "\nUsers of SYNERGY-ChangeBase: (Total of 11 licenses issued; Total of %-2d", changebaselicences
print " licences in use)"
printf "\nUsers of SYNERGY-CMBase: (Total of 12 licenses issued; Total of %-2d", cmbaselicences
print " licences in use)"
print ""
print " NOTE: It is not possible to terminate SYNERGY-ChangeBase licences"
print ""
}
here's a little better version - a desired formatting is left as an exercise:
nawk '
BEGIN {
cmdYP="ypmatch"
SEPyp=":"
}
{
if (gsub("[(]linger: 1800[)]", "ChangeBase"))
chb++
else {
$0=$0 OFS "CMBase"
cmb++
}
cmd=cmdYP OFS $4 OFS "passwd"
cmd | getline yp
close(cmd)
user=(split(yp, ypA, SEPyp))? ypA[5] : "unknown"
print $4, $8, $9, $11, $12, user
}
END {
printf("\nUsers of SYNERGY-ChangeBase: (Total of 11 licenses issued; Total of %-2d licences in use)\n", chb)
printf("Users of SYNERGY-CMBase: (Total of 12 licenses issued; Total of %-2d licences in use)\n", cmb)
print " NOTE: It is not possible to terminate SYNERGY-ChangeBase licences\n"
}' myFile