Jump to content

Script for changing all users password on zimbra for Richa Global

From TetraWiki

Script for Changing password for all user on richaglobal and abcleather.com[edit]

Process[edit]

Create sudo user richa as below

richa ALL=(zimbra) NOPASSWD: /home/richa/pass-change-richaglobal.sh, /home/richa/pass-change-abcleathers.sh

Where pass-change-richaglobal.sh and pass-change-abcleathers.sh are the scripts to change passwords on 2 domains .


The Sample Scripts are

#!/bin/bash
MYDOMAIN="richaglobal.com"
NEWPASS="newpass"
TEMPFILE="/tmp/list.txt"
CMDFILE="/tmp/changepw.cmd"
# Create the work files and set appropriate permissions.
touch ${TEMPFILE}
touch ${CMDFILE}
chmod 0600 ${TEMPFILE}
chmod 0600 ${CMDFILE}
# This will create a list of users in Zimbra for the specified domain.
#su - zimbra -c "zmprov -l getAllAccounts ${MYDOMAIN} > ${TEMPFILE}"
/opt/zimbra/bin/zmprov -l getAllAccounts ${MYDOMAIN} > ${TEMPFILE}
# This will loop through the users and create a password reset command file.
while read -a LINE ; do
echo "modifyAccount ${LINE[0]} userPassword ${NEWPASS}" >> ${CMDFILE}
done < ${TEMPFILE}
rm ${TEMPFILE}


Change " Domain " and "Password" as per the requirement .

Process of Running the Script[edit]

  1. Change the "Newpass" with actual password .
  2. Run it by ./pass-change-richaglobal.sh or ./pass-change-abcleathers.sh
  3. This will create 2 files '/tmp/list.txt" and "/tmp/changepw.cmd"
  4. '/tmp/list.txt" will contain list of all users , one on each line
  5. "/tmp/changepw.cmd" will contain the command for the modifying the password like "modifyAccount vaibhav@richaglobal.com userPassword newpass"
  6. Then run
/opt/zimbra/bin/zmprov < /tmp/changepw.cmd

Check the users for password change .