Here's something I hacked up a while ago to expire entries from the bounces
list. I like to remove entries after they are a month old. I run this once
a week.... I can't decide whether to call it expire_bounces or prune_bounces.
'prune' won when I wrote it.... Note that there is so much similarity with
the bounce program, perhaps it should just be merged with the 'bounce'
program.
John, please put this in the next release, or bug me to merge it with
'bounce', if you think that's the way to go....
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: prune_bounces.pl
# Wrapped by pdc@lunch.engr.sgi.com on Mon Jan 30 11:19:54 1995
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f prune_bounces.pl -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"prune_bounces.pl\"
else
echo shar: Extracting \"prune_bounces.pl\" \(2194 characters\)
sed "s/^X//" >prune_bounces.pl <<'END_OF_prune_bounces.pl'
X#!/usr/bin/perl
X#
X# Prune the bounces list, removing all entries older than a certain age.
X# Relies on the name format as set by the bounce program:
X# name@host (date list-name)
X#
X# date is in the form yymmdd.
X#
X# Note: there is so much similarity with the bounce program, perhaps it
X# should just be merged with bounce.
X#
X# Paul Close, Nov 16, 1994
X#
X
X$maxage = 30; # maximum age in days
X@days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
X
X##user.name@host.com (941116 list-name)
X
Xrequire "getopts.pl";
X
X&Getopts("b:df:") ||
X die("USAGE: $0 -b bounces_list [-f <config-file>] [-d]\nStopped");
X
Xdie "Must specify -b bouce_list_location\n" unless $opt_b;
X
Xif (! defined($opt_f)) {
X $opt_f = <~/.majordomo>;
X}
X
X&read_config();
X
X$bounce_passwd = $passwd{'bounces'};
Xif (! $bounce_passwd || ! $majordomo{'bounces'}) {
X die("no password for list bounces; stopping");
X}
X
Xlocal($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
X
X# simplified leap year detection, but works until the year 2100!
Xif ($year % 4 == 0) {
X $days[1] = 29;
X}
X
X$mday -= $maxage;
Xwhile ($mday <= 0) {
X $mon--;
X if ($mon < 0) {
X $mon += 12;
X $year--;
X }
X $mday += $days[$mon];
X}
X$expire = int(sprintf("%02d%02d%02d", $year, $mon+1, $mday));
X
Xif (defined($opt_d)) {
X print "\nexpiring entries older than $expire\n\n";
X open(MSG, ">&STDOUT");
X} else {
X open(MSG, "|/usr/lib/sendmail $majordomo{'bounces'}") ||
X die("open(MSG, \"|/usr/lib/sendmail $majordomo{'bounces'}\"): $!\nStopped");
X}
X
Xprint MSG <<EOF;
XTo: $majordomo{'bounces'}
XSubject: expired bounces entries
X
XEOF
X
Xopen(BOUNCES, "<$opt_b") || die "open(BOUNCES, \"<$opt_b\"): $!";
X
Xwhile (<BOUNCES>) {
X next unless /\((\d+) \w+.*\)/;
X if ($1 <= $expire) {
X printf MSG "approve %s unsubscribe bounces %s", $bounce_passwd, $_;
X }
X}
X
Xprint MSG "end\n";
Xclose(MSG);
X
X# from the bounce program
Xsub read_config {
X open(CONF, $opt_f) || die("open(CONF, \"$opt_f\"): $!");
X while (<CONF>) {
X s/\n$//;
X s/#.*//;
X if (/^$/) { next; }
X split;
X $_[0] =~ tr/A-Z/a-z/;
X $_[2] =~ tr/A-Z/a-z/;
X $passwd{$_[0]} = $_[1];
X $passwd{"$_[0]@$_[2]"} = $_[1];
X $majordomo{$_[0]} = $_[2];
X }
X close(CONF);
X}
X
END_OF_prune_bounces.pl
if test 2194 -ne `wc -c <prune_bounces.pl`; then
echo shar: \"prune_bounces.pl\" unpacked with wrong size!
fi
chmod +x prune_bounces.pl
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
--
Paul Close pdc@sgi.com http://reality.sgi.com/employees/pdc/
No fate but what we make
|
|