#!/bin/sh
###
###  Copyright (C) 1998-2010 by the Free Software Foundation, Inc.
###
###  This program is free software; you can redistribute it and/or
###  modify it under the terms of the GNU General Public License
###  as published by the Free Software Foundation; either version 2
###  of the License, or (at your option) any later version.
###
###  This program is distributed in the hope that it will be useful,
###  but WITHOUT ANY WARRANTY; without even the implied warranty of
###  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
###  GNU General Public License for more details.
###
###  You should have received a copy of the GNU General Public License
###  along with this program; if not, write to the Free Software
###  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
###  02110-1301, USA. http://www.fsf.org/licensing/licenses/gpl.html
###
###  ---------------------------
###
###  Simple script meant to run periodically via cron, uses the
###  Mailman bin program "list_members" on a group of mailing lists to
###  save the listing of all subscribers to a temporary file for each
###  list, then uses scp to copy the files to a different server.
###
###  Relies on ssh key files being exchanged beforehand so that scp
###  won't require login info for each copy.  Google ssh passwordless
###  login for more information about setting this up, if necessary.
###
###  Author: Anthony R. Thompson
###  Contact: put @ between art and sigilservices.com
###  Created: Dec 2009
###

MM_BIN_DIR=/usr/lib/mailman/bin                           # INSTALL
SAVE_DIR=$HOME/who                                        # INSTALL

# INSTALL; note, if you use ~ or $HOME here, it will refer to THIS
# user's environment, not remote user's, so absolute paths work best.
REMOTE_SAVE_DIR=user@server:/path/to/remote/save/dir      # INSTALL

for list in `$MM_BIN_DIR/list_lists -b | egrep -v '^mailman$'`; do $MM_BIN_DIR/list_members -r -d -f -p $list > $SAVE_DIR/$list.list; done

# Only redirects STDOUT, if there are errors they'll print to Cron
scp $SAVE_DIR/*.list $REMOTE_SAVE_DIR > /dev/null
