Return to Snippet

Revision: 33974
at January 16, 2012 04:19 by uptimejeff


Updated Code
#!/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

Revision: 33973
at January 16, 2012 04:16 by uptimejeff


Updated Code
#!/bin/bash

# Group EMail Enabler v0.2
# Jeff Johnson <[email protected]>

# OS X Server should allow you to create a Group in Work Group Manager
# and allow you to email that group. This functionality is missing or broken
# in most versions of OS X Server

# This script allows you to manage email groups using Work Group Manager.
# If you create a 'manager' group in WGM, you then have a manager@ email address
# automatically maintained as you adjust the members

# To achieve this, 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.

# If you use these installation instructions, the script will run every 5 minutes.

# 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

Revision: 33972
at October 21, 2010 11:46 by uptimejeff


Updated Code
#!/bin/bash

# Group Email Enabler is a simple script which fixes a shortcoming in OS X Server 10.6
# by allowing each WGM group to automatically become an email list for it's members.
#
# Jeff Johnson    [email protected]
#
 
# To install
#  1. save this file as
#         /usr/sbin/group_email.sh
#  2. sudo chmod +x /usr/sbin/group_email.sh
#  3. touch /private/var/log/group_email.log
#  4. adjust /etc/postfix/main.cf, add the following to "alias_maps="
#         hash:/etc/postfix/group_aliases
#  5. add the following to /etc/crontab (you may need to create /etc/crontab)
#         */15 * * * * root /usr/sbin/group_email.sh >> /private/var/log/group_email.log

# To use
#  When the script runs, it searches for any WGM group in /LDAPv3/127.0.0.1 the word "mail"
#  within the comment field. Postfix aliases with group members are then created.
#
#  If you create a group called 'employees' and put all staff in that group, you will
#  then have an email setup of [email protected]
#  
#  Be sure all mail groups contain at least one member

# Would like to add/modify
# 1. needs error trapping. a group without members returns an error.
# 2. support for non-local LDAP


# clear current aliases
echo "" > /etc/postfix/group_aliases

# 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"` >> /etc/postfix/group_aliases
   done

/usr/sbin/postalias /etc/postfix/group_aliases
/usr/bin/newaliases
exit 0

Revision: 33971
at October 16, 2010 01:57 by uptimejeff


Updated Code
#!/bin/bash

# Group Email Enabler is a simple script which fixes a shortcoming in OS X Server 10.6
# by allowing each WGM group to automatically become an email list for it's members.
#
# Jeff Johnson    [email protected]
#
 
# To install
#  1. save this file as
#         /usr/sbin/group_email.sh
#  2. sudo chmod +x /usr/sbin/group_email.sh
#  3. touch /private/var/log/group_email.log
#  4. adjust /etc/postfix/main.cf, add the following to "alias_maps="
#         hash:/etc/postfix/group_aliases
#  5. add the following to /etc/crontab (you may need to create /etc/crontab)
#         */15 * * * * root /usr/sbin/group_email.sh >> /private/var/log/group_email.log

# To use
#  When the script runs, it searches for any WGM group in /LDAPv3/127.0.0.1 with it's
#  comment set to exactly 'mail'. It then creates postfix aliases with the group short name
#  and includes the group's members.
#  If you create a group called 'employees' and put all staff in that group, you will
#  then have an email setup of [email protected]
#  
#  Be sure all mail groups contain at least one member

# Would like to add/modify
# 1. lookup groups that 'contain' the word mail in comments instead of comments equals mail.
# 2. needs error trapping. a group without members returns an error.
# 3. support for non-local LDAP


# clear current aliases
echo "" > /etc/postfix/group_aliases

# Get list of groups with 'mail' in the comment field
gr=`dscl /LDAPv3/127.0.0.1 -search /Groups Comment mail | grep Comment | cut -f1`

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"` >> /etc/postfix/group_aliases
   done

/usr/sbin/postalias /etc/postfix/group_aliases
/usr/bin/newaliases
exit 0

Revision: 33970
at October 15, 2010 08:17 by uptimejeff


Updated Code
#!/bin/bash

# Group Email Enabler is a simple script which fixes a shortcoming in OS X Server 10.6
# by allowing each WGM group to automatically become an email list for it's members.
#
# Jeff Johnson    [email protected]
#
 
# To install
#  1. save this file as
#         /usr/sbin/group_email.sh
#  2. sudo chmod +x /usr/sbin/group_email.sh
#  3. touch /private/var/log/group_email.log
#  4. adjust /etc/postfix/main.cf, add the following to alias_maps
#         hash:/etc/postfix/group_aliases
#  5. add the following to /etc/crontab
#         */15 * * * * root /usr/sbin/group_email.sh >> /private/var/log/group_email.log

# To use
#  Any WGM group in /LDAPv3/127.0.0.1 with it's comment set to exactly 'mail'
#  will have a mail alias setup within 15 minutes on execution of this script.
#  If you follow the install instructions, the group emails will be updated every 15 minutes
#  Be sure all mail groups contain at least one member

# Would like to add/modify
# 1. lookup groups that 'contain' the word mail in comments instead of comments equals mail.
# 2. needs error trapping. a group without members returns an error.
# 3. support for non-local LDAP


# clear current aliases
echo "" > /etc/postfix/group_aliases

# Get list of groups with 'mail' in the comment field
gr=`dscl /LDAPv3/127.0.0.1 -search /Groups Comment mail | grep Comment | cut -f1`

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"` >> /etc/postfix/group_aliases
   done

/usr/sbin/postalias /etc/postfix/group_aliases
/usr/bin/newaliases
exit 0

Revision: 33969
at October 15, 2010 08:13 by uptimejeff


Updated Code
#!/bin/bash


# To install
#  1. save this file as
#         /usr/sbin/group_email.sh
#  2. sudo chmod +x /usr/sbin/group_email.sh
#  3. touch /private/var/log/group_email.log
#  4. adjust /etc/postfix/main.cf, add the following to alias_maps
#         hash:/etc/postfix/group_aliases
#  5. add the following to /etc/crontab
#         */15 * * * * root /usr/sbin/group_email.sh >> /private/var/log/group_email.log

# To use
#  Any group with 'mail' as the comment will have a mail alias setup within 15 minutes
#  Be sure all mail groups contain at least one member

# Would like to add/modify
# 1. lookup groups that 'contain' the word mail in comments instead of comments equals mail.
# 2. needs error trapping. a group without members returns an error.
# 3. support for non-local LDAP


# clear current aliases
echo "" > /etc/postfix/group_aliases

# Get list of groups with 'mail' in the comment field
gr=`dscl /LDAPv3/127.0.0.1 -search /Groups Comment mail | grep Comment | cut -f1`

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"` >> /etc/postfix/group_aliases
   done

/usr/sbin/postalias /etc/postfix/group_aliases
/usr/bin/newaliases
exit 0

Revision: 33968
at October 15, 2010 07:50 by uptimejeff


Updated Code
#!/bin/bash


# To install
#  1. save this file as
#         /usr/sbin/group_email.sh
#  2. sudo chmod +x /usr/sbin/group_email.sh
#  3. touch /private/var/log/group_email.log
#  4. adjust /etc/postfix/main.cf, add the following to alias_maps
#         hash:/etc/postfix/group_aliases
#  5. add the following to /etc/crontab
#         */15 * * * * root /usr/sbin/group_email.sh >> /private/var/log/group_email.log

# clear current aliases
echo "" > /etc/postfix/group_aliases

# Get list of groups with 'mail' in the comment field
gr=`dscl /LDAPv3/127.0.0.1 -search /Groups Comment mail | grep Comment | cut -f1`

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"` >> /etc/postfix/group_aliases
   done

/usr/sbin/postalias /etc/postfix/group_aliases
/usr/bin/newaliases
exit 0

Revision: 33967
at October 15, 2010 07:48 by uptimejeff


Initial Code
#!/bin/bash

# clear current aliases
echo "" > /etc/postfix/group_aliases

# Get list of groups with 'mail' in the comment field
gr=`dscl /LDAPv3/127.0.0.1 -search /Groups Comment mail | grep Comment | cut -f1`

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"` >> /etc/postfix/group_aliases
   done

/usr/sbin/postalias /etc/postfix/group_aliases
/usr/bin/newaliases
exit 0

Initial URL

                                

Initial Description
If you have any contributions, please comment here.

Initial Title
OSX Server - Group EMail Enabler v0.2

Initial Tags
mail, server, osx

Initial Language
Bash