-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccounts.pl
81 lines (77 loc) · 2.93 KB
/
accounts.pl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr//bin/perl
#
# Script to balance accounts between servers
#
use warnings;
START:print "\nOperations:
1. List Mail Store servers
2. List total number of accounts
3. List total numbers of account per server
4. List disk usage per server (time consuming) NOT DONE
5. Redistribute users by number of accounts per server
Select your operation: ";
$answer = <STDIN>;
if ($answer == 1) {
print "\nChecking for Zimbra Mail Store servers\n";
$mailStoreServers = `zmprov gas mailbox`;
$numbersOfMailServers = $mailStoreServers =~ tr/\n//;
print "Found $numbersOfMailServers servers:\n";
print "$mailStoreServers";
goto START
} elsif ($answer == 2) {
print "\nChecking for total numbers of accounts\n";
$numbersOfAccounts = `zmprov -l gaa|wc -l`;
print "Total numbers of accounts: $numbersOfAccounts";
goto START
} elsif ($answer == 3) {
print "\nChecking for total numbers of accounts per server\n";
$numbersOfAccounts = `zmprov -l gaa|wc -l`;
my @lines = split /\n/, `zmprov gas mailbox`;
foreach my $line (@lines) {
$count = `zmprov -l gaa -s $line |wc -l`;
$percent = ($count*100)/$numbersOfAccounts;
$percent = sprintf("%.1f", $percent);
# $count = chomp ($count); This does not work as intended yet
print "$line: $count ($percent%)\n";
}
goto START
} elsif ($answer == 4) {
print "\nChecking disk usage per user, per server\n";
$mailStoreServers = `zmprov gas mailbox`;
my @lines = split /\n/, `zmprov gas mailbox`;
foreach my $line (@lines) {
$count = `zmprov -l gaa -s $line |wc -l`;
$percent = ($count*100)/$numbersOfAccounts;
$percent = sprintf("%.1f", $percent);
print "$line: $count ($percent%)\n";
}
goto START
} elsif ($answer == 5) {
print "\nChecking for total numbers of accounts per server\n";
$numbersOfAccounts = `zmprov -l gaa|wc -l`;
$mailStoreServers = `zmprov gas mailbox`;
$numbersOfMailServers = $mailStoreServers =~ tr/\n//;
my @lines = split /\n/, `zmprov gas mailbox`;
foreach my $line (@lines) {
$count = `zmprov -l gaa -s $line |wc -l`;
$percent = ($count*100)/$numbersOfAccounts;
$percent = sprintf("%.1f", $percent);
# $count = chomp ($count); This does not work as intended yet
print "$line: $count ($percent%)\n";
$shouldHave = $numbersOfAccounts / $numbersOfMailServers;
$shouldHave = sprintf("%.0f", $shouldHave);
print "$line should have $shouldHave numbers of account, but currently have $count.\n\n";
$result = $shouldHave - $count;
if ($result == abs($result)) {
print "This server should get accounts";
#place commands for transfering accounts
} elsif ($result != abs($result)) {
print "This server should have less accounts";
#let servers who need accounts do the pickup
}
}
print "Starting relocating accounts...";
} else {
print "Your selection is not valid\n";
goto START
}