From 108f074bf223a4550336f9c9c066ef02bd75f6c0 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 8 Apr 2015 11:12:13 -0400 Subject: [PATCH] Adding collection-hq scripts Signed-off-by: Bill Erickson --- KCLS/utility-scripts/collection_hq/crontab | 4 ++ KCLS/utility-scripts/collection_hq/extract.sh | 58 ++++++++++++++++++++++++ KCLS/utility-scripts/collection_hq/get_bibs.sql | 22 +++++++++ KCLS/utility-scripts/collection_hq/get_items.sql | 22 +++++++++ KCLS/utility-scripts/collection_hq/send-email.pl | 53 ++++++++++++++++++++++ 5 files changed, 159 insertions(+) create mode 100644 KCLS/utility-scripts/collection_hq/crontab create mode 100755 KCLS/utility-scripts/collection_hq/extract.sh create mode 100644 KCLS/utility-scripts/collection_hq/get_bibs.sql create mode 100644 KCLS/utility-scripts/collection_hq/get_items.sql create mode 100755 KCLS/utility-scripts/collection_hq/send-email.pl diff --git a/KCLS/utility-scripts/collection_hq/crontab b/KCLS/utility-scripts/collection_hq/crontab new file mode 100644 index 0000000000..fcba1ca114 --- /dev/null +++ b/KCLS/utility-scripts/collection_hq/crontab @@ -0,0 +1,4 @@ + +# change FTPUSER AND FTPPASS to suit +0 2 20 * * cd /home/opensrf/Evergreen/KCLS/misc-scripts/collectionHQ && FTPUSER= && FTPPASS= ./extract.sh + diff --git a/KCLS/utility-scripts/collection_hq/extract.sh b/KCLS/utility-scripts/collection_hq/extract.sh new file mode 100755 index 0000000000..d00946f287 --- /dev/null +++ b/KCLS/utility-scripts/collection_hq/extract.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +LIBRARYNAME="KINGCOUNTY" +DATE=`date +%Y%m%d` +FILE="$LIBRARYNAME""$DATE".DAT +# FTPUSER=""" -- passed via command line +# FTPPASS="" -- passed via command line +FTPSITE="ftp.collectionhq.com" +EMAILFROM="collectionHQ@kcls.org" +EMAILTO="amoroni@kcls.org,bbonner@kcls.org,mcarlson@kcls.org" + +function get_data_from_sql { + echo The extract for $DATE has begun. | ./send-email.pl --from "$EMAILFROM" --to "$EMAILTO" --subject "collectionHQ extraction has begun" + date + echo "Pre-warming the cache" + echo Fetching bibs... + psql -A -t -U evergreen < get_bibs.sql 2>&1 | cut -c8- | perl -ne 'if (m/^[0-9]/) { print STDERR; } else { print; }' > bibs-$DATE.txt + date + echo Fetching items... + psql -A -t -U evergreen < get_items.sql 2>&1 | cut -c8- | perl -ne 'if (m/^[0-9]/) { print STDERR; } else { print; }' > items-$DATE.txt + date + echo done. +} + +function format_data { + echo "##HEADER##,##DAT##,##${DATE}##,##${LIBRARYNAME}##,,,##USA##" > $FILE + cat bibs-$DATE.txt >> $FILE + cat items-$DATE.txt >> $FILE + NUMBIBS=`wc -l bibs-$DATE.txt | cut -d' ' -f1` + NUMITEMS=`wc -l items-$DATE.txt | cut -d' ' -f1` + echo "##TRAILER##,$NUMBIBS,$NUMITEMS" >> $FILE +} + +function upload_data { + gzip --best $FILE + ftp -v -n $FTPSITE < +-- Galen Charlton +-- +-- Original version sponsored by the King County Library System +-- +-- 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 + +SET statement_timeout = 0; +SELECT collectionHQ.write_bib_rows_to_stdout('KINGCOUNTY',1); diff --git a/KCLS/utility-scripts/collection_hq/get_items.sql b/KCLS/utility-scripts/collection_hq/get_items.sql new file mode 100644 index 0000000000..0dd52c2b58 --- /dev/null +++ b/KCLS/utility-scripts/collection_hq/get_items.sql @@ -0,0 +1,22 @@ +-- Copyright (C) 2011-2012 Equinox Software Inc. +-- Ben Ostrowsky +-- Galen Charlton +-- +-- Original version sponsored by the King County Library System +-- +-- 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 + +SET statement_timeout = 0; +SELECT collectionHQ.write_item_rows_to_stdout('KINGCOUNTY',1); diff --git a/KCLS/utility-scripts/collection_hq/send-email.pl b/KCLS/utility-scripts/collection_hq/send-email.pl new file mode 100755 index 0000000000..1b0a0248cd --- /dev/null +++ b/KCLS/utility-scripts/collection_hq/send-email.pl @@ -0,0 +1,53 @@ +#!/usr/bin/perl -w + +use strict; +use Email::Sender::Simple qw(sendmail); +use Email::Simple; +use Email::Simple::Creator; +use Email::Sender::Transport::SMTP qw(); +use Getopt::Long; + +my $to = 'esi@localhost.localdomain'; +my $from = $to; +my $subject = ""; +my $body = ""; + +my $result = GetOptions ( + "to=s" => \$to, + "from=s" => \$from, + "subject=s" => \$subject +); + +my $transport = Email::Sender::Transport::SMTP->new ({ + host => 'smtp.kcls.org', + port => 25 +}); + +while (<>) { $body .= $_; } + +my $email = Email::Simple->create( + header => [ + To => $to, + From => $from, + Subject => $subject, + ], + body => $body, +); + +sendmail($email, { transport => $transport }); + +=head1 NAME + +send-email.pl + +=head1 USAGE + +echo Hello world! | \ + + send-email.pl \ + + --from '"Ben Ostrowsky" ' \ + + --to '"Ben Ostrowsky" , "Someone Else" ' \ + + --subject "Stuff" -- 2.11.0