[root@tcs9 scripts]# cat mailboxes.pl
#!/usr/bin/env perl
#
use strict;
use warnings;
use Statistics::Descriptive;
use integer;
my @quota;
my @numbers;
my @geomeans;
my $sum;
my $product = "1";
my $id=getpwuid($<);
#Esnure that zimbra user is being used
chomp $id;
if ($id ne "zimbra")
{
print STDERR "Error: must be run as zimbra user\n";
exit (1);
}
my $count = `zmprov gqu \`zmhostname\` | wc -l`;
my $stat0 = Statistics::Descriptive::Full->new();
my $stat1 = Statistics::Descriptive::Full->new();
open(QUO,"zmprov gqu `zmhostname` |") || die "Failed: $!\n";
while ( <QUO> )
{
push(@quota, $_);
}
foreach my $quota (@quota)
{
chomp $quota;
my ($user, $limit, $actual) = split(/ /, $quota);
push (@numbers, $actual);
$sum += $actual;
}
my $arrSize = @quota;
foreach my $numbers(@numbers)
{
if ($numbers == 0)
{
push (@geomeans, "1");
}
else
{
push (@geomeans, $numbers);
}
}
$stat0->add_data(@numbers); my $mean = $stat0->mean();
$stat1->add_data(@geomeans); my $geo = $stat1->geometric_mean();
$mean = int($mean);
$geo = int($geo);
$mean = ($mean / 1024 ) / 1024;
$geo = $geo / 1024;
chomp $count;
print "Mailboxes: " . $count . "\n";
print "Means: " . $mean . " MB\n";
print "Geomeans: " . $geo . " KB\n";
__END__