Managing UCSC mailing lists with Blanche and Perl
If you manage mailing lists at UCSC you need to know about blanche. Of course it is kinda hard to
find out about blanche, see: http://its.ucsc.edu/services/web/unix/blanche
To really learn about Blanche log into unix.ucsc.edu and type blanche -h
I use blanche for it's -f feature. Which allows you to pass a mailing list and a path to a file containing email addresses (or user names). It uses the passed file as the new members of the list. I like to know who people are, so I use a file that has all of my lists with names and info in it, and then run a perl script that creates individual files of members and calls blanche -f on each of those lists.
Steps of My Mailing list management
- Created Dated copy of Master List (for history)
- Manage Master List text file - add and subtract members
- Upload Master List to unix.ucsc.edu
- Run Update Mailing Lists perl script
My Master List File
Here is a portion of my tab delimitated file. The only thing that is used by the system is the list and the email/user name. The rest is to keep track of who is who.
Start Role List Name Email/User 2006 student danm-students Luke McLastname mb-REDACTED-ck 2006 student danm-students Andres McLastname a-REDACTED-jas 2004 student danm-students Adam McLastname a-REDACTED-ugim@adobe.com 2005 student danm-students Nici McLastname n-REDACTED-sixx@gmail.com 2007 guest danm-alumni Fokko McLastname f-REDACTED-o 2007 guest danm-alumni Satadru McLastname s-REDACTED-d@gmail.com 2006 student danm-alumni 2006 Student List danm-students06 2004 student danm-alumni 2004 Student List danm-students04 2005 student danm-alumni 2005 Student List danm-students05 2003 staff danm-alumni Felicia McLastname f-REDACTED-ice 2002 staff danm-alumni Lyle McLastname l-REDACTED-e 2007 staff danm-alumni Chris McLastname c-REDACTED-ai 2007 staff danm-faculty Chris McLastname c-REDACTED-ai 2007 facutly danm-faculty Gustavo McLastname g-REDACTED-zquez 2007 facutly danm-faculty Patty McLastname p-REDACTED-llagh 2007 facutly danm-faculty Soraya McLastname s-REDACTED-urray ???? faculty danm-faculty Ben McLastname b-REDACTED-j@gmail.com ???? faculty danm-faculty Cathy McLastname c-REDACTED-oussl ???? faculty danm-faculty David McLastname d-REDACTED- ???? faculty danm-faculty Paul McLastname d-REDACTED-sbark ???? faculty danm-faculty David McLastname d-REDACTED-raneI like to know what year someone started, their basic roll and their name. As you can see some of the email/user values are UCSC user names, some are email addresses and some are other list names. All of which blanche will be able to use.
Perl Script
The perl script opens the mailing-lists.txt file and creates a temparary file using the list name. Using the document above the script would make these files:
- danm-students.tmp
- danm-alumni.tmp
- danm-faculty.tmp
Here is the source code to my update_mailing_lists.pl script.
print "Erasing the temparary email list (list-name.tmp) files.\n";
@files = <*.tmp>;
foreach $file (@files) {
unlink($file);
}
print "Opening the Master Email List file (mailing-lists.txt).\n";
open(MEMBERS, "mailing-lists.txt");
@file = <MEMBERS>;
close(MEMBERS);
$headers = shift(@file);
print "adding users to temparary email list .tmp files...\n";
foreach $line (@file){
#this is a gready split, so multile tabs are taken at once
#this means you must have a value for every column
# and you can add lots of tabs between columns to make the
# document look cleen.
($year, $role, $list, $name, $email) = split(/[\t]+/, $line);
# this gets rid of the caraige return from the last line.
chomp($email);
# you can uncomment this print to see what is being collected
#print $year . " " . $list . " " . $name . " " . $email . "\n";
# this is way inafficent becuase it has to open and close
# files for every entry. That means that each temp email list file
# is open multiple times
open(TMP, ">>$list.tmp");
print TMP $email."\n";
close(TMP);
# this gives some feedback that something is going on
print ".";
}
print "\n\n";
@files = <*.tmp>;
foreach $file (@files) {
($list, $ext) = split(/\./, $file);
print "updating $list email list by running:\n";
print " blanche $list -f $file\n";
`blanche $list -f $file`;
}
print "\nDone adding people to lists.\n";
exit;
Run It
Make sure you understand my code before you use this little guy. The command via ssh is:
perl update_mailing_list.plAnd your master mailing-list.txt file must be named in that fashion. Also, my match on tabs is greedy, so you can have multiple tabs for each delimitation, and you must have values in every "field".
My email/username is lyle, if you have questions please feel free to ask. -Lyle