Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com

This Blog is protected by DMCA.com

huuphan.com. Powered by Blogger.

zimbra create multiple accounts csv file

I will writing the script for create multiple accounts from csv file.
  1. To create Accounts.csv file
  2. To use bash script create multiple accounts in zimbra
  3. To execute zimbra_account.sh bash script
I'm created Accounts.csv file
# cat Accounts.csv 
The content Accounts.csv file as below:
[email protected],123456789,Huu1,Phan Van,Phan Van Huu1 (IT),mail.huuphan.local
[email protected],123456789,Huu2,Phan Van,Phan Van Huu2 (IT),mail.huuphan.local

zimbra create multiple accounts csv file full script

zimbra create multiple accounts with zimbra_account.sh name
#!/bin/bash
# File Accounts.csv as below:
# [email protected],123456789,Huu1,Phan Van,Phan Van Huu1 (IT),mail.huuphan.local
# [email protected],123456789,Huu2,Phan Van,Phan Van Huu2 (IT),mail.huuphan.local
DATE=$(date)
OLDIFS=$IFS
IFS=','
File_Name="/opt/Account/Accounts.csv"
Out_log='/tmp/outfile.log'
        echo "$DATE - To create account Email" | tee $Out_log
        echo "Account, Password, First_Name, Last_Name, DisplayName, zimbraMailHost" | tee -a $Out_log
while read Acount_Email Password First_Name Last_Name Display_Name Mailbox
do
        echo "$Acount_Email, $Password, $First_Name, $Last_Name, $Display_Name, $Mailbox" | tee -a $Out_log
        echo ""
Uid=$(echo $Acount_Email | cut -d '@' -f1)
Domain=$(echo $Acount_Email | cut -d '@' -f2)
su - zimbra -c "zmprov -l gaa | grep '\b$Uid'@$Domain"
if [ $? -eq 0 ] ; then
        echo "$Acount_Email exits"
else
        su - zimbra -c "zmprov ca '$Acount_Email' '$Password' givenName '$First_Name' sn '$Last_Name' displayName '$Display_Name' zimbraMailHost '$Mailbox'" >>$Out_log
fi

done < ${File_Name}
IFS=$OLDIFS
To execute bash script
#./zimbra_account.sh


post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com