forked from stsimb/zimbra-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzimbra-size.sh
executable file
·62 lines (55 loc) · 2.14 KB
/
zimbra-size.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# script to report zimbra mailbox size per folder for a specific user
# based on info at http://www.zimbra.com/forums/administrators/23655-per-folder-size-command-line.html#post121758
# stsimb feb 2014
PATH=/opt/zimbra/bin:/bin:/usr/bin
if [ "$(id -un)x" != "zimbrax" ]; then
echo "Fatal error: This script needs to run as user zimbra."
exit 1
fi
if [ $# == 0 ] ; then
echo "Report zimbra mailbox size per folder for a specific user"
echo
echo "Usage = $0 username"
echo
exit 1
fi
USER=$1
backend="$(zmprov ga ${USER} zimbraMailHost | tail -2 | awk '{print $2}')"
if [ "${backend}x" != "$(zmhostname)x" ]; then
echo "Fatal error: need to run on ${backend} for ${USER}."
exit 1
fi
quota="$(expr `zmprov ga ${USER} zimbraMailQuota | tail -2 | awk '{print $2}'` / 1024 / 1024)"
size="$(zmmailbox -z -m ${USER} gms)"
echo "${USER}'s max mailbox size = ${quota} MB, current mailbox size = ${size}."
echo
TF=$(mktemp)
zimbraID="$(zmprov ga ${USER} zimbraID | tail -2 | awk '{print $2}')"
rm -f ${TF}
zmmailbox -z -m ${USER} gaf | grep mess | egrep -v "\(.*@.*:2\)" > ${TF}
echo "size (MB) msgcount unread folder"
echo "--------- --------- ---------- ----------------------------"
while read line ; do
folder="$(echo ${line} | awk '{print $5,$6,$7,$8,$9}')"
msgcount="$(echo ${line} | awk '{print $4}')"
unread="$(echo ${line} | awk '{print $3}')"
fid=$(echo ${line} | awk '{print $1}')
if [ ! -z "${fid##*[!0-9]*}" ]; then
if [ "x${msgcount}" != "x0" ]; then
mboxinfo=$(mysql -N -e "select id, group_id from zimbra.mailbox where account_id=\"${zimbraID}\"")
mboxid=$(echo ${mboxinfo} | awk '{print $1}')
gid=$(echo ${mboxinfo} | awk '{print $2}')
info=$(mysql -N -e "select size, metadata from mboxgroup${gid}.mail_item where mailbox_id=${mboxid} and id=${fid}")
size=$(echo ${info} | egrep -o ":szi.*:" | cut -d: -f2 | cut -c 4- | sed -e 's/e4$//')
sizeMB="$(expr ${size} / 1024 / 1024 2>/dev/null)" # || echo 0)"
else
sizeMB="0"
fi
printf "%9s %9s %10s " ${sizeMB} ${msgcount} ${unread}
echo ${folder}
# else
# echo "${folder} is shared, skipping"
fi
done < ${TF}
rm -f ${TF}