/ Published in: Bash
If you have any contributions, please comment here.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/bin/bash # Group EMail Enabler v0.2 # Jeff Johnson <[email protected]> # Tested with OS X Server 10.6 and 10.7 # Should also work with 10.5 # This script allows you to manage email groups using Work Group Manager. # If you create an executive group in WGM, you then have a executive@ email address # This is automatically maintained as you adjust the members # The script searches your LDAP groups for the word 'mail' in the comment field # You must add mail to the comment field for any group which should have an email address. # The email address for that group will be the shortname of that group. # If you miss this step (add 'mail' to the comment field), this script does nothing. # Known issues # 1. Only supports groups in LDAP, users can be in LDAP or Local # 2. Does not support other groups within your email group (no nested groups) # 3. Almost no error checking, so best to run it manually a few times to check results. # Installation Instructions # 1. Save this file as # /usr/sbin/group_email.sh # 2. Then adjust permissions # sudo chmod +x /usr/sbin/group_email.sh # 3. Modifiy alias_maps in /etc/postfix/main.cf # You need to add this line to what you already have # hash:/etc/postfix/group_aliases # Example, you have: # alias_maps = hash:/etc/aliases # Change to: # alias_maps = hash:/etc/aliases, hash:/etc/postfix/group_aliases # 4. To run automatically every 5 minutes, I prefer a simple addition to /etc/crontab # you may need to create /etc/crontab if it doesn't exist # Add the following to /etc/crontab # */5 * * * * root /usr/sbin/group_email.sh >> /dev/null 2>&1 # # If you followed these instructions, within 5 minutes you will see an alias file at # /etc/postfix/groupaliases # you can inspect the file to confirm the results. cd /etc/postfix # clear current aliases echo "" > group_aliases.tmp # Get list of groups with 'mail' in the comment field gr=`dscl /LDAPv3/127.0.0.1 -list /Groups Comment | grep mail | awk '{print $1}'` for group in $gr do echo $group: `dscl /LDAPv3/127.0.0.1 -read /Groups/$group dsAttrTypeNative:memberUid | cut -d : -f 3 | grep -v "No such key"` >> group_aliases.tmp done cmp -s group_aliases.tmp group_aliases > /dev/null if [ $? -eq 1 ]; then echo different cp group_aliases.tmp group_aliases /usr/sbin/postalias /etc/postfix/group_aliases /usr/bin/newaliases else echo same fi exit