-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-quota-usage.sh
47 lines (25 loc) · 909 Bytes
/
check-quota-usage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
my $hostname = localhost;
my @quotas = `zmprov gqu $hostname`;
foreach my $quotaline(@quotas)
{
chop($quotaline);
my ($email, $quota, $usage) = split(' ', $quotaline);
$quota=utils_convert_bytes_to_optimal_unit($quota);
if($quota == "0 Bytes") {
$quota="Unlimited";
}
$usage=utils_convert_bytes_to_optimal_unit($usage);
print "$email,$usage,$quota\n";
}
sub utils_convert_bytes_to_optimal_unit{
my($bytes) = @_;
return '' if $bytes eq '';
my $size;
$size = $bytes . ' Bytes' if $bytes < 1024;
$size = sprintf("%.2f", $bytes/1024) . ' KB' if $bytes >= 1024 && $bytes < 1048576;
$size = sprintf("%.2f", $bytes/1048576) . ' MB' if $bytes >= 1048576 && $bytes < 1073741824;
$size = sprintf("%.2f", $bytes/1073741824) . ' GB' if $bytes >= 1073741824 && $bytes < 1099511627776;
$size = sprintf("%.2f", $bytes/1099511627776) . ' TB' if $bytes >= 1099511627776;
return $size;
}