[Mailman-Users] Subscribing to List 1 automatically subscribes user to List 2

Raymond Wood raywood at magma.ca
Mon May 5 16:24:40 CEST 2003

On Tue, Apr 15, 2003 at 04:45:29PM -0400, Jon Carnes remarked:

> On Tue, 2003-04-15 at 13:27, Raymond Wood wrote:
> > Hello mailman-users,
> > 
> > I'm writing to ask your collective advice about how best to
> > arrange it so that when a user subscribes to one list (say,
> > MAIN), then they automatically get subscribed to a second
> > list (say, ANNOUNCE).
> > 
> > One issue here is that there may be people who want to
> > subscribe to ANNOUNCE who do not want to subscribe to MAIN
> > :)  Otherwise a solution would likely be much easier to
> > find...
> > 
> > Here are some ideas that have surfaced:
> > 
> > 2.  Hack together some shell script, run as a cron job, that
> >     would automatically subscribe MAIN newcomers to the ANNOUNCE
> >     list.

> This is my choice.  You can use the mailman commands (in
> ~mailman/bin/..) to help you write the script:
>   list_members - this will show the email address subscribed to a list
>   add_members - this will add users to a list
> You could periodically (every hour) dump out the email
> addresses from Main, then use that list to do an add_member to
> Announce.  Mailman won't add the same user twice, so it will
> ignore duplicates and only add any new users.

Thanks for your feedback.  Based on it, a successful solution
was created -- see below.

> I have a feeling that you want Announce to be a list of all
> your users (no matter what list they are on).  In that case, I
> would use list_members to dump out the email addresses from
> each of the lists into one big file, then use: sync_members to
> add/delete users from the list Announce.
> The Umbrella FAQ entry has a script that does this very nicely!

This would work except that there are instances of subscriptions
to our Announce list who were not necessarily subscribed to any
other list.  AFAICT the danger of using the 'sync_members'
command above is that it will remove addresses from a list if
they are not contained in the input file.  Because of this my
preference was to use the 'add_members' command instead (which
you also mentioned above).

I based my script largely on the Umbrella FAQ entry at:

I changed the script to use the 'add-members' command, modified
the comments, and changed a few other little details along the
way to get things to work smoothly for me.

Below is the final script:
NOTE: Replace all instances of the word 'string' below with the
      main name of your mailing lists.


-----  8<  -----------------------------------------------------


# TITLE:    
# CREDITS:  Based on a script (author unknown) found at:
#           http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq03.005.htp
# DESCRIP:  Aggregates all mailing list subscriber email addresses, from all
#           mailing lists; then adds them to the 'string-announce' list 
#           (duplicate addy's already existing on the string-announce list are 
#           ignored/unaffected).
# NOTES:    o intended to be run as a system-wide cron job once/hour.

# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Have cron run this script hourly and the 'string-announce' list will be
# updated automatically every hour with all the latest mailing
# list email addresses from ALL 'string-' mailing lists.
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# ===================================================================
# Create an empty file
# ===================================================================
echo " " > /tmp/lists-subscribers

# ===================================================================
# Extract all mailing list names that contain the word 'string'
# (i.e. all mailing lists, case insensitive) and dump them to a
# file, but be sure to not include either the "string-announce"
# or "string-test" lists.
# ===================================================================
/usr/lib/mailman/bin/list_lists | grep -i string | grep -vi string-announce | grep -vi string-test | awk '{ print $1 }' > /tmp/lists

# ===================================================================
# For all mailing lists contained in the file above, dump all
# subscriber email addresses to a different file.
# ===================================================================
for i in `cat /tmp/lists`
   /usr/lib/mailman/bin/list_members $i >> /tmp/lists-subscribers

# ===================================================================
# Sort the list, remove duplicate entries, and write to yet another
# file.
# ===================================================================
cat /tmp/lists-subscribers |sort -u > /tmp/lists-subscribers_sorted

# ===================================================================
# Feed the list of ALL 'string-' list subscribers into the 'string-announce' list.
# NOTE: Welcome messages need not be turned off for the
#       'string-announce' list, since running this script will *not*
#       send the list members a welcome message, (i.e. the script
#       temporarily overrides whatever the list's regular
#       'send_welcome_msg' configuration setting is.
# ===================================================================
/usr/lib/mailman/bin/add_members -n /tmp/lists-subscribers_sorted -w n string-announce > /dev/null

# ===================================================================
# Clean up /tmp files...
rm -f /tmp/lists
rm -f /tmp/lists-subscribers
rm -f /tmp/lists-subscribers_sorted
# ===================================================================

# ===================================================================
# Done!
# ===================================================================
#echo ""
#echo 'Mailing list string-announce has been updated -- Done!'
#echo ""

-----  >8  -----------------------------------------------------

More information about the Mailman-Users mailing list