Listing 4
BEGIN {
# define input field delimiter as :
FS=":"
# Initialize
BSCOUNT=0
CSCOUNT=0
KSCOUNT=0
OSCOUNT=0
TOTAL=0
# Heading
print "--------------"
print "Parsing user info from FILENAME"
print "--------------"
}
{
# ignore system entries without login shells
if(length($7) == 0) {
printf "Skipping: %s\n", $0
next
}
TOTAL++
# Examine 7th field in record
if( index($7, "/sh") > 0)
++BSCOUNT
else if( index($7, "/ksh") > 0)
++KSCOUNT
else if( index($7, "/csh") > 0)
++CSCOUNT
else
++OSCOUNT
}
END {
# Print out summaries
print "==========="
if(TOTAL > 0) {
printf "Bourne Shell: %d Users %.0f %%\n",
BSCOUNT, (BSCOUNT / TOTAL) * 100
printf "Korn Shell: %d Users %.0f %%\n",
KSCOUNT, (KSCOUNT / TOTAL) * 100
printf "C Shell: %d Users %.0f %%\n",
CSCOUNT, (CSCOUNT / TOTAL) * 100
printf "Other Shell: %d Users %.0f %%\n",
OSCOUNT, (OSCOUNT / TOTAL) * 100
}
print "-----------"
printf "Total Number of users polled: %d\n",
TOTAL
print "============="
}
Copyright © 1994 - 2019 Linux Journal. All rights reserved.