domingo, 12 de septiembre de 2010

Script para la creación automática de los directorios de los usuarios de correo


Una vez hemos instalado y configurado nuestro servidor de correo debemos crear los directorios de los usuarios. Dentro del apéndice correspondiente al servidor de correo, he copiado este script realizado por Sergio Gon´zalez para automatizar la tarea.
Cada vez que se añada un usuario deberemos ejecutar el usuario como root con lo que crearemos la estrucutura de directorios Maildir en su directorio particular o /home/vmail/$user si no es un usuario del dominio.


#!/bin/sh
#
# Copyright (C) 2004 Sergio González González <sergio.gonzalez@hispalinux.es>
#
# Depends on:
# - ldapsearch
# - maildirmake ( from courier )
#
# Based on http://jeroen.protheus.com/postfix-courier-ldap-howto.html
# (c) J.Vriesman
#
# and
#
# Based on http://bulma.net/body.phtml?nIdNoticia=2013
# (c) Jesús Roncero Franco

#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Password to bind to ldap server
systempass="1234"
# Bind dn
binddn="ou=Postfix,dc=mczones,dc=es"
# Acount leave
accountleave="ou=usuarios,dc=mczones,dc=es"
# ldap host
ldaphost="servidorubuntu.mczones.es"
# Maildir name
maildir="Maildir/"
# Mail users home name
homedir="/home/vmail"
# Mail user's group
group="vmail"
usernames=`ldapsearch -h $ldaphost -x -w $systempass -D "$binddn" \
-b "$accountleave" "(!(quota=-1))" uid \
| grep "^[^#]" | grep "^[^dn]" | grep uid | awk '{ print $2 }'`
# create personal mailfolders
for username in $usernames
do
homedirectory=`ldapsearch -h $ldaphost -x -w $systempass -D "$binddn" \
-b "$accountleave" "(uid=$username)" homeDirectory \
| grep "^[^#]" | grep homeDirectory | grep "$homedir" \
| awk '{ print $2 }'`
if [ ! -d $homedirectory/$maildir ] && [ ! -z $homedirectory ]
then
mkdir -p -m 2750 $homedirectory
maildirmake $homedirectory/$maildir
if [ ! -f $homedirectory/.procmailrc ]
then
echo -ne "PATH=/usr/bin:/bin:/usr/local/bin:.\nMAILDIR=\$HOME/Maildir\n\
DEFAULT=\$MAILDIR/" > $homedirectory/.procmailrc
fi
chown -R $username.$group $homedirectory
fi
done

para continuar viendo el resto de manuales Linux siga el enlace:administración de servidores con Linux

No hay comentarios: