分类: BSD
2007-11-19 16:44:19
复制后保存成文件,比如文件名为:create_mail_ldap_user.sh。
Global Setting 区域中的几个变量需要根据实际情况进行修改。使用方法:
# # chmod +x create_mail_ldap_user.sh # # ./create_mail_ldap_user.sh USERNAME # # -------------- OR ---------------- # ./create_mail_ldap_user.sh USER1 USER2 USER3... #
完整的脚本代码:
#!/bin/sh # File: create_mail_ldap_user.sh # Version: 0.1.1 # Author: Bibby(michaelbibby#gmail.com) # Date: 2007.11.18 # Purpose: Add new LDAP user for postfix mail server. # Use vim: # :set tabstop=4 # :set shiftwidth=4 # # Changelog: # 0.1 -> 0.1.1: # * Add maildrop/quota support. # 0.1: init version. usage() { echo -e "\n\tUsage: $0 USERNAME" echo -e "\t\t$0 USER1 USER2 USER3...\n" } # BASE_DN, DOMAIN_DN: # The full DN will be: # # uid=${USERNAME}, ${DOMAIN_DN}, ${BASE_DN} # # such as: # # uid=bibby, o=domain1.com, o=domains,dc=bibby,dc=org # _____ ___________ _________________________ # /|\ /|\ /|\ # | | | # USERNAME DOMAIN BASE_DN # # Setting 'BASE_DN'. BASE_DN="o=domains,dc=bibby,dc=org" # Setting 'DOMAIN' and DOMAIN_DN': # * DOMAIN will be used in mail address: ${USERNAME}@${DOMAIN} # * DOMAIN_DN will be used in LDAP dn. DOMAIN="domain1.com" DOMAIN_DN="o=domain1.com" # ---------- rootdn of LDAP Server ---------- # Setting rootdn of LDAP. ROOTDN='cn=Manager,dc=bibby,dc=org' # Setting rootpw of LDAP. ROOTPW="bibby" # ---------- LDAP User Setting -------------- # Setting Maildir name. MAILDIR='Maildir' # HOME directory for LDAP user. # mailbox of LDAP user will be: # ${HOME_DIR}/${DOMAIN}/${USERNAME}/Maildir/ # Such as: # /home/vmail/domains/domain1.com/bibby/Maildir/ # -------------------|===========|-----| # HOME_DIR | DOMAIN | USERNAME # HOME_DIR="/home/vmail/domains" # Set default quota for LDAP users. QUOTA='10000000S' # Set default password for LDAP users. DEFAULT_PASSWD='123456' # ---------- Welcome Mail info ------------- # Set welcome mail info. WELCOME_MSG_TITLE="Welcome!" WELCOME_MSG_BODY="Thanks for your use." # ------------------------------------------- # ----------- End Global Setting ------------ # ------------------------------------------- add_new_user() { # Create template LDIF file for this new user and add it. # If you do *NOT* want to keep rootpw in script, use '-W' instead of # '-w "${ROOTPW}". ldapadd -x -D "${ROOTDN}" -w "${ROOTPW}" <