#!/usr/bin/env bash # # Fetches all users and aliases from MySQL # For import in other backup MX config. # # Requires a .my.cnf with this content: # [client] # password=foo BACKUPMX_USER=/home/backupmx MAIL_ADDR=$(mysql -sN -u root mailserver -e "SELECT email from virtual_users UNION SELECT source FROM virtual_aliases;" | sort | uniq) # Makes a list of all mail addresses (be it real or aliases) for i in $MAIL_ADDR; do echo -e "$i\tOK" done > $BACKUPMX_USER/relay_recipients_$(cat /etc/mailname) # Generates list of all domains for i in $MAIL_ADDR; do echo $i | cut -d'@' -f2 done | sort | uniq > $BACKUPMX_USER/domains_$(cat /etc/mailname)