inuseby.awk
Generated on Tue Dec 05 17:39:05 Eastern Standard Time 2006 from inuseby.awk
# Program : INUSEBY.AWK
# Purpose : Parse through GWCHECK Contents log for "kbytes in use by user's mail"
# Author : Bob Jonkman <bjonkman@sobac.com>
# Copyright 2008 Bob Jonkman and/or SOBAC Microcomputer Services
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Date : 9 February 2005 ( Gung Hei Fat Choi!)
BEGIN { OFS = "," ;
Mebi = 1024*1024 ; # http://en.wikipedia.org/wiki/Binary_prefix
print("From the GWCHECK.LOG file(s) ") ;
}
/Processed on/ { print("\n") ;
print($0) ; # print date & time of processing
}
/Path to PO/ # print Path to PO
/Post Office=/ { print($0) ; # print PO name
postoffice = $NF ; # Postoffice name is the last field
}
/Verify / { if ($3 == "Contents")
correctfile = 1 ;
}
/Checking user/ { count++ ; # Count the number of items
ObjectIDstart = index($0,$4) ;
ObjectIDend = index($0,"(") ;
ObjectID[count] = substr($0, ObjectIDstart, ObjectIDend - ObjectIDstart) "." postoffice ;
}
/kbytes in use by user's mail/ { array[count] = $1 ; # Store them to calculate variance later
total += $1 ; # Keep a running total
}
END { if(!correctfile)
{ print("\n\n" FILENAME " is not a GWCHECK Contents log file!") ;
print(FILENAME " is not a GWCHECK Contents log file!") > "/dev/stderr" ;
}
else if(!count)
{ print("\n\n No user database entries with bytes in use!") ;
print("No user database entries with bytes in use!") > "/dev/stderr" ;
}
else
{ print( "\n") ;
print("KiBytes in use, ObjectID.PO") ;
mean = total / count ;
printf("%14i,%s\n", mean, "Mean (Average) ==============") | "sort /R" ;
# Calculate sample variance
# http://mathworld.wolfram.com/SampleVariance.html
#
# variance = (1/count)* sum of (array[i] - m) ^2
#
#
for(i=1; i <= count; i++)
{ if(array[i] > max) max = array[i] ;
variance += (array[i] - mean)^2 ;
printf("%14i,%s\n", array[i], ObjectID[i]) | "sort /R" ;
}
variance /= count ;
# Standard Deviation is sqrt(variance) == variance ^ (1/2)
sigma = variance ^ .5 ;
highsigma = (max - mean) / sigma ;
for(i=1; i < highsigma ; i++)
printf("%14i,%s\n", i*sigma + mean, i " Sigma ================") | "sort /R" ;
print("=====\n");
printf("%14i, Total KiBytes\n", total);
printf("%14.2f, Total GiBytes\n", total/Mebi);
print("\n") ;
printf("%14i, Average KiBytes in use\n", mean);
printf("%14i, Number of objects\n", count);
printf("%14i, Variance\n", variance);
printf("%14i, Standard Deviation\n",sigma);
}
}
# EOF: INUSEBY.AWK
1 files processed.