Tuesday, March 2, 2010

getAccounts from Zimbra

Script to get account details from your zimbra mail server along with aliases. In our scenario, we did this for creating accounts in new server based on the information from the old server. The ouput file will be in the format below.
-------------------------------------
Email address:alias1,alias1
Email address2:alias1

-------------------------------------

Remarks: In this script, it will take only accounts in the active and locked state.

#!/bin/bash
#Declare name of output file in the variable below:
file=accountlist;
echo "" > $file;

for line in `zmprov gaa`;
do
status=`zmprov ga $line|grep 'zimbraAccountStatus:'|cut -d : -f 2`;
if [ $status == "active" ]||[ $status == "locked" ];
then
name=$line;
aliases='';
zmprov ga $name|grep 'zimbraMailAlias' > tmp3.txt;
for line1 in `sed 's/zimbraMailAlias://g' tmp3.txt`;
do
aliases=$line1','$aliases;
done
echo $name:$aliases >> $file;
sed -i '/^$/d' $file;
echo "" > tmp3.txt;
fi
done

No comments:

Post a Comment