#!/usr/bin/perl use DBI; use Time::Local; # checkEmbargo # checks InfoTrack.bornDigital table dateAvailable field # locates any embargos about to lift # emails Shawn Averkamp, Janet Lee-Smeltzer, and myself to notify us of the raising embargo # so record can be uploaded into OPAC and so I can ensure the content is copied live to Acumen. # jody DeRidder 10/19/09 ## Copyright (c) 2010, The University of Alabama Libraries. ## Contributed by Jody DeRidder, 7/30/10. ## All rights reserved. ## Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ## * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. ## * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in ## the documentation and/or other materials provided with the distribution. ## * Neither the name of The University of Alabama Libraries nor the names of its contributors may be used to endorse or promote products ## derived from this software without specific prior written permission. ##THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ##THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ##CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ##PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ##LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ##EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #@emails = ("jlderidder\@ua.edu"); @emails = ("saverkamp\@ua.edu", "jleesmeltzer\@ua.edu", "jlderidder\@ua.edu"); $out = "/srv/scripts/etds/embargoLift.txt"; unlink $out; open(OUT, ">".$out) or die "can't write to message\n"; $hostname = "localhost"; $port = "3306"; $user = "user"; $password = "password"; $database = "InfoTrack"; ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime; $year += 1900; $mon += 1; # this makes it this month # we want next month. $mon += 1; if ($mon > 12){ $mon = "01"; $year += 1;} elsif ($mon =~ /^[1-9]{1}$/){ $mon = "0".$mon;} #if ($mday =~ /^[1-9]{1}$/){ $mday = "0".$mday;} #$if ($hour =~ /^[1-9]{1}$/){ $hour = "0".$hour;} #if ($min =~ /^[1-9]{1}$/){ $min = "0".$min;} #if ($sec =~ /^[1-9]{1}$/){ $sec = "0".$sec;} # we're going to run this the 21st of each month, and look for things whose embargo lifts # on the first day of the following month. #print "testing for $year-$mon-01\n"; #:$hour $min $sec\n"; $today = "$year-$mon-$mday"; $test ="$year-$mon-01"; $dbh = DBI->connect("DBI:mysql:$database:$hostname", #:$port", $user, $password) or die "can't connect to database: ",$DBI::errstr,"\n"; $h->{PrintError} = 1; $h->{RaiseError} = 1; $mydate = $dbh->quote($test); $sth = $dbh->prepare("select id_2009, lastName, firstName, title, datestamp, dateAvailable from bornDigital where dateAvailable like $mydate") #$sth = $dbh->prepare("select id_2009, lastName, firstName, title, datestamp, dateAvailable from bornDigital where dateAvailable > $mydate") or die "can't prepare select ",$dbh->errstr(),"\n"; $sth->execute() or die "Can't select from InfoTrack : ", $sth->errstr(),"\n"; $count = 1; while (($id, $last, $first, $title, $stamp, $avail) = $sth->fetchrow_array()){ if ($count eq 1){ print OUT "Date_Web_Available\tAssigned_Filename\tAuthor\tTitle\tDate_Processed\n"; } $count ++; $avail =~ s,\-,,g; # remove hyphens, she wants yyyymmdd print OUT "$avail\t$id\t$last, $first\t$title\t$stamp\n"; } close(OUT); $sth->finish(); $dbh->disconnect(); $mess = "/srv/scripts/etds/message"; open (MESS, ">".$mess) or die "can't write a message\n"; print MESS "Please see attached list; these ETDs should be processed for the catalog. Thank you!\n"; close(MESS); if (-s $out){ # if it exists and has non-zero size $subject = q("NOTIFICATION of Embargo lifting for ETDs"); foreach $e (@emails){ `mail -s $subject -a $out $e < $mess`; } } $username="user2"; $password="password2"; $mynum = 8; $dbh = DBI->connect ("dbi:mysql:checkscripts:content.lib.ua.edu", $username, $password) or &sendmessage; $h->{PrintError} = 1; $h->{RaiserError} = 1; $mynum = $dbh->quote($mynum); $sth= $dbh->prepare("insert into ran values(NULL,$mynum,NULL,NULL)"); $sth->execute or die "can't insert into checkscripts: ",$dbh->errstr(),"\n"; $sth->finish; $dbh->disconnect(); exit; sub sendmessage{ $message = "can't get to checkscripts on encompass from EmbargoCheck on libcontent1\n"; $tellme = ">./summessage"; $tellwhat = "./summessage"; open (TELL, $tellme); print TELL $message; close(TELL); $subject = q("CAN'T get to checkscripts on encompass FROM libcontent1"); `mail -s $subject "jlderidder\@ua.edu" < $tellwhat`; exit; }