Skip to Content.
Sympa Menu

en - [sympa-users] Re: Re: Re: How to unsubscribe people from a list from the command line

Subject: The mailing list for listmasters using Sympa

List archive

Chronological Thread  
  • From: elijah <address@concealed>
  • To: "address@concealed" <address@concealed>
  • Subject: [sympa-users] Re: Re: Re: How to unsubscribe people from a list from the command line
  • Date: Fri, 27 Apr 2007 16:37:26 -0700

Tim Koop wrote:

> If the command line is not an option, I don't mind poking into Sympa's
> database myself. Can somebody confirm that a simple delete of a record
> in subscriber_table would do the trick, even while Sympa is in the
> middle of a mailing?

We do it too different ways: the "sympa" way, using a perl script to
call sympa, and the "brute force" way, using a bash script to make
direct database calls.

Both are attached. (list.common is required for user.unsubscribe [perl],
and common is required for remove_user [sh]). These scripts could use a
lot of help, if you were so inclined.

-elijah
#!/bin/sh

export DB_USER=`grep "^db_user" /etc/sympa/sympa.conf | cut -f2`
export DB_NAME=`grep "^db_name" /etc/sympa/sympa.conf | cut -f2`
export DB_PASS=`grep "^db_pass" /etc/sympa/sympa.conf | cut -f2`

#!/usr/bin/perl

##
## a common inlude file for
## the command line versions of list
## commands
##


use lib '/home/sympa/bin';
use Conf; # to load Sympa conf which is needed by List.pm
use List;
use Log; # if you want to get logs of List.pm

# Load the Sympa configuration :
unless (Conf::load('/etc/sympa/sympa.conf')) {
print STDERR "Can't load Sympa configuration file";
exit 1;
}

# If you want to get logs of List.pm
# &do_openlog($Conf{'syslog'}, $Conf{'log_socket_type'}, 'sympa');

# check availabity of Sympa database
if ($Conf{'db_name'} and $Conf{'db_type'}) {
unless ($List::use_db = &List::probe_db()) {
print STDERR "Sympa can't connect to database";
exit 1;
}
}
&List::_apply_defaults(); # else reading of a List configuration won't work

#!/bin/sh


if [ $# -lt 2 ]; then
echo "Usage: remove_user address@concealed list_name"
echo "example: remove_user address@concealed test"
echo " (special listname 'ALL' can be used to unsubscribe user from
all lists) "
exit 1
fi

source /home/sympa/tools/common


if [ "$2" == "ALL" ]; then
LISTS=`mysql -s -u $DB_USER -p$DB_PASS --batch --database=$DB_NAME \
--execute "select list_subscriber from subscriber_table where
user_subscriber='$1'";`
echo "removing $1 from:"
echo "$LISTS"
mysql -u $DB_USER -p$DB_PASS --batch --database=$DB_NAME --execute
"delete from subscriber_table where user_subscriber='$1'"

else
# First see if the user actually is a member of that list

USER=`mysql -s -u $DB_USER -p$DB_PASS --batch --database=$DB_NAME \
--execute "select user_subscriber from subscriber_table where \
user_subscriber='$1' and list_subscriber='$2'";`

LIST=`mysql -s -u $DB_USER -p$DB_PASS --batch --database=$DB_NAME \
--execute "select list_subscriber from subscriber_table where \
user_subscriber='$1' and list_subscriber='$2'";`

if [ "$1" = "$USER" -a $2 = "$LIST" ]
then
echo "Found: $USER subscribed to $LIST"
echo -n "Removing.... "

mysql -u $DB_USER -p$DB_PASS --batch --database=$DB_NAME
--execute \
"delete from subscriber_table where user_subscriber='$1' \
and list_subscriber='$2'";

echo "done."
else
echo "$1 was not found to be subscribed to $2!"
exit 1
fi
fi
#!/usr/bin/perl

##
## command line script to remove a list of users
## usage:
## cat users | user.unsubscribe <listname>
##

if ($#ARGV != 0) {
print "usage:\n cat <file of emails> | user.unsubscribe <listname>\n\n";
exit;
}
require 'list.common';

my $list = new List($ARGV[0]);

## dump subscribers backup file
#$list->_save_users_file("$list->{'dir'}/subscribers.dump");

## Delete users
my @users;
while (<STDIN>) {
print 'unsubscribe ', $_;
chop;
push @users, $_;
}
$list->delete_user(@users);



Archive powered by MHonArc 2.6.19+.

Top of Page