Skip to content

Instantly share code, notes, and snippets.

@shazaum
Forked from ognjenm/export.sh
Created May 9, 2017 12:07
Show Gist options
  • Save shazaum/f953b9bd5350326e0391f5dd13bd5383 to your computer and use it in GitHub Desktop.
Save shazaum/f953b9bd5350326e0391f5dd13bd5383 to your computer and use it in GitHub Desktop.
The following script will export all zimbra accounts to an import script
#!/bin/bash
# The following script will export all accounts to an import script.
# this script should be run as zimbra user
# target for ZCS 8, single server deployment
# last update 2014-04-04
# ognjen.miletic@gmail.com
# original at http://www.3open.org/d/zimbra/export_accounts
# customize these to your needs
# work folder must be writable by zimbra
work_folder=/tmp
import_script=${work_folder}/accounts-import.sh
brojac=0
# reset files:
echo "Kreiram prazan fajl ${import_script}";
echo '' > ${import_script}
echo "Eksportujem listu korisnika...";
# get all account to $accounts
accounts=`zmprov -l gaa | egrep -v 'admin|wiki|galsync|spam|ham|virus|stimpson'`;
echo "Gotovo";
echo "Kreiram import skript...";
# loop for each account
for account in ${accounts}; do
echo "${brojac} Eksportujem nalog ${account} ..."
dn=`zmprov -l ga ${account} displayName | grep displayName | sed 's/displayName: //'`;
up=`zmprov -l ga ${account} userPassword | grep userPassword | sed 's/userPassword: //'`;
# generate import script
echo "echo 'Import korisnika ${account}'" >> ${import_script}
echo "zmprov ca ${account} ${up} displayName '${dn}'" >> ${import_script}
echo "zmprov ma ${account} userPassword '${up}'" >> ${import_script}
# add blank line separator
echo '' >> ${import_script}
let brojac=brojac+1
done
echo "Eksport gotov.";
echo "Import skript je na putanji ${import_script}";
echo "Kopirajte ga na novi server i pokrenite";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment