User Tools

Site Tools


scripts:zimbra:dump-distributon-list-membership.sh
dump-distribution-list-membership.sh
#!/bin/bash
# Written by Thomas York
 
# Dumps distribution lists and distribution list membership to a file for recreation
# Check to make sure the supplied an argument to the script
if [ "x$1" == "x" ] ; then
        echo "Usage:";
        echo "         $0 <backup file>";
        echo "";
        exit 1;
fi
 
# Assign some constants
readonly OUTPUTFILE=$1;
 
# Clear output file
echo -n "" > $OUTPUTFILE;
 
# Get list of distribution lists from the server and iterate through it
for GADLOUTPUT in $(sudo -E -u zimbra /opt/zimbra/bin/zmprov gadl); do
	# Write to file..
	echo -ne "$GADLOUTPUT ->" >> $OUTPUTFILE;
 
	# Get list of accounts in each distribution list
	for GDLOUTPUT in $(sudo -E -u zimbra /opt/zimbra/bin/zmprov gdl $GADLOUTPUT | grep zimbraMailForwardingAddress | awk '{print $2}'); do
		# Write to file..
		echo -ne " $GDLOUTPUT" >> $OUTPUTFILE;
	done
	echo -ne "\n" >> $OUTPUTFILE;
done
/usr/local/www/vhost/www.fuhell.com/data/pages/scripts/zimbra/dump-distributon-list-membership.sh.txt · Last modified: 2014/09/01 15:00 (external edit)