// you’re reading...

Linux, Unix, and Solaris

How to use Bash to extract Qmail accounts for OpenSRS import

Since I happen to be going through the pain of a bulk migration from Qmail to OpenSRS, I figured I can’t be the only one. Here’s a Bash script I wrote to extract Qmail users accounts into a CSV file. Enjoy!

#!/bin/bash
#
#
# Simple Email Account Extractor for Qmail
# - Extracts username/password into a CSV file
# - Format: local_user,remote_user,remote_password,remote_server,remote_port,migration_type,skip_list,translate_list
#   e.g.    foo@bar.com,foo@bar.com,abc123,imap.oldmail.com,143,imap4,,
#
# @author http://randymelder.com/
#
#
IMAPHOST=imap.youroldemailhost.com
IMAPPORT=143
IMAPV=imap4
# CSV file your want to flush to
OUTFILE=/tmp/migration_accounts.csv
# default account name
POSTMASTER=postmaster
# executables folder
VPOPMAILBIN=/home/vpopmail/bin
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # #   DO NOT EDIT BELOW THIS POINT  # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
NOW=`date +"%Y-%m-%d %H:%M:%S"`
# Test the binary folder
if [ -e $VPOPMAILBIN ] 
then
echo "[$NOW] $VPOPMAILBIN found, proceeding..."
else
echo "[$NOW] Can't find $VPOPMAILBIN, exiting..."
exit
fi
# Get all the domains
DOMAINS=`$VPOPMAILBIN/vdominfo -n | awk '{ print $1 }'`
NOW=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$NOW] Domains found in your vpopmail database:"
echo $DOMAINS
# Get names in domain
for d in $DOMAINS; 
do
USERS=`$VPOPMAILBIN/vuserinfo -D $d -n`
for u in $USERS; 
do
if [ "$u" != "$POSTMASTER" ]
then 
# Get pw for user:
EMAIL="$u@$d"
PASSWORD=`$VPOPMAILBIN/vuserinfo -C $EMAIL`
echo "$EMAIL,$EMAIL,$PASSWORD,$IMAPHOST,$IMAPPORT,$IMAPV,," >> $OUTFILE
fi
done;
done;
NOW=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$NOW] Sending email account CSV to: $OUTFILE"

Discussion

No comments for “How to use Bash to extract Qmail accounts for OpenSRS import”

Post a comment

Help support my site and buy a domain name at http://domainsemailhosting.com/