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:
huupv1@mail.huuphan.local,123456789,Huu1,Phan Van,Phan Van Huu1 (IT),mail.huuphan.local
huupv2@mail.huuphan.local,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:
# huupv1@mail.huuphan.local,123456789,Huu1,Phan Van,Phan Van Huu1 (IT),mail.huuphan.local
# huupv2@mail.huuphan.local,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


Comments

  1. ERROR: service.INVALID_REQUEST (invalid request: must be valid email address: account)

    I am getting such an error can cause problems

    ReplyDelete
  2. I have same error. ERROR: service.INVALID_REQUEST (invalid request: must be valid email address: account)

    ReplyDelete
  3. Hello,

    I can't solve problem below. Hostname is true. Can you help me ?

    ERROR: service.INVALID_REQUEST (invalid request: specified zimbraMailHost does not correspond to a valid server service hostname: mail.xxx.xxx)

    ReplyDelete

Post a Comment

Popular posts from this blog

Bash script list all IP addresses connected to Server with Country Information

zimbra some services are not running [Solve problem]

Whitelist and Blacklist domain in zimbra 8.6