We maintain a number of Mailman mailing lists. One of the reasons that I like Mailman for listserv-type functions is that it is easily scriptable from the command line. Here’s an example.
At the end of each academic year, we like to remind list owners of lists that are no longer being used, so that we can remove unnecessary lists and/or make arrangements to transfer ownership of lists to new groups. Here’s an easy way to generate a CSV file showing the name of the mailing list, the last time a message was sent via the mailing list and the owner(s) of the list.
In the mailman binary directory (on an older version of CentOS, it’s
/usr/local/mailman/bin/; yours is probably different), create a file called last_post.py. Here’s what to put in the file:
#!/usr/bin/env python ''' Last time a message was posted to a list, along with list name ''' import os import time DEBUG = 0 print "List,Last Post Date,Owner(s)" def last_post(mlist): last = time.strftime('%m-%d-%Y',time.localtime(mlist.last_post_time)) owner = '' try: if len(mlist.owner)>1: owner = ';'.join(mlist.owner) else: owner = mlist.owner except IndexError: owner = 'email@example.com' print "%s,%s,%s" % ( mlist.real_name, last, owner) return
Now that you have the
last_post.py file, you invoke it from the command line like this:
./withlist -a -r last_post.last_post >/tmp/last_posts.txt
This runs the withlist command (a utility bundled with mailman and located in the same directory) on all (“-a”) lists. The command tells it to run (“-r”) the function that you’ve created (“last_post”) located in the file that you’ve created (“last_post”), directing the output to
/tmp/last_posts.txt. Note that you do not specify the file extension for the last_post.py file. You should see some output fly by as the program is being executed. When you open up the
/tmp/last_posts.txt file, you’ll see something like this:
List,Last Post Date,Owner Mailman,05-27-2010,firstname.lastname@example.org Fdesoc,04-07-2010,joanna.XXXXX@YYY.com ALASA,05-27-2010,y342@ZZZ.edu Fmeet,05-27-2010,email@example.com;firstname.lastname@example.org;email@example.com;firstname.lastname@example.org ...
You can then use this csv file as the basis for sending out reminder messages, etc.