Skip to content

Instantly share code, notes, and snippets.

@gordyt
Created January 30, 2020 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gordyt/e88dc2d7cd2464f75915f4f05cb75233 to your computer and use it in GitHub Desktop.
Save gordyt/e88dc2d7cd2464f75915f4f05cb75233 to your computer and use it in GitHub Desktop.
An easy way to check mailbox affinity assignment for users in Zimbra-X
#!/bin/bash
prefix="test"
domain="zmc.com"
ilen=1
mls=$(kubectl get services | grep zmc-mls | awk '{print $3}')
declare -A mboxes
for pinfo in $(kubectl get pods -o wide | grep zmc-mailbox | awk '{printf("%s:%s\n", $6, $1)}'); do
IFS=: read ip host <<< $pinfo
mboxes["$ip"]="$host"
done
function usage {
echo "usage: $0 -p <prefix> -d <domain> [-z] <num-users>"
echo "defaults:"
echo "- prefix=$prefix"
echo "- domain=$domain"
echo ""
echo "If you include -z option, will zero-pad the user index so all are the same length."
echo "For example, if you ask for 100 users to be checked, and you specify the -z option,"
echo "then the email addresses will look like this: ${prefix}001@${domain} - ${prefix}100@${domain}."
echo "Without the -z option they will look like this: ${prefix}1@${domain} - ${prefix}100@${domain}."
exit 1
}
pad_users=false
while getopts ":p:d:zh" opt; do
case ${opt} in
p )
prefix=$OPTARG
;;
d )
domain=$OPTARG
;;
z )
pad_users=true
;;
h )
usage
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
usage
;;
: )
echo "Invalid option: $OPTARG requires an argument" 1>&2
usage
;;
esac
done
shift $((OPTIND -1))
num_users="$1"
if [ -z "${num_users}" ]; then
echo "must specify number of users"
usage
fi
check_user() {
u="$1"
ip=$(curl -ks https://$mls:7072/search?email=$u)
echo "${mboxes[$ip]}"
}
if [ $pad_users == true ]; then
ilen=$(expr length $num_users)
fi
i=1
while [ $i -le $num_users ]; do
ii=$(printf "%0${ilen}d" $i)
u="${prefix}$ii@${domain}"
host=$(check_user $u)
echo -e "$u\t$host"
i=$(expr $i + 1)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment