Scripts to help with template email and upload.
authorRobin H. Johnson <rjohnson@sitka.bclibraries.ca>
Thu, 23 Feb 2012 02:34:07 +0000 (18:34 -0800)
committerRobin H. Johnson <rjohnson@sitka.bclibraries.ca>
Thu, 23 Feb 2012 02:34:07 +0000 (18:34 -0800)
marc_export_custom/email-template.sh [new file with mode: 0755]
marc_export_custom/stats.pl [new file with mode: 0755]
marc_export_custom/stats.sh [new file with mode: 0755]
marc_export_custom/upload.lftp [new file with mode: 0755]

diff --git a/marc_export_custom/email-template.sh b/marc_export_custom/email-template.sh
new file mode 100755 (executable)
index 0000000..2127c4a
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/bash
+t1=$1
+t1=${t1/T/ }
+t1=${t1/??Z}
+t2=$2
+t2=${t2/T/ }
+t2=${t2/??Z}
+
+if [ -z "$t1" -o -z "$t2" ]; then
+       echo "Usage: $0 'Generate timestamp' 'Submit timestamp'" 1>&2
+fi
+
+cat <<EOF
+Date: $(date -uR)
+From: "Robin H. Johnson" <rjohnson@sitka.bclibraries.ca>
+Subject: SITKA Outlook export $(date +%Y/%m/%d -d "$t1") (includes ELN media/serials)
+To: Anne Morgan <anne.morgan@bclibrary.ca>, Ramiro Castillo <rcr@auto-graphics.com>, Heather Morrison <heatherm@eln.bc.ca>
+Cc: "Robin H. Johnson" <rjohnson@sitka.bclibraries.ca>, Ben Hyman <ben.hyman@cooperative.bclibraries.ca>, sherbert@sitka.bclibraries.ca
+
+Full automated Outlook export
+
+Notes:
+Apologies about the delay, I went and worked on a lot of bugs.
+After the Autographics code generate the next set of FAILEDFILTER and REJECT
+entries are generated (James & Mark fixed entries for me back in December), I'm
+going to start feeding most of those into an exclusion list so we can flag them
+for further fixing while not sending them to Autographics until then.
+These exports are smaller than the previous round by a good 10%, of records
+that were weird or shouldn't have been in the export in the first place (like
+SPRUCE holdings).
+Anne: The full list of SITKA shortcodes, including the branch suffixes you
+requested, is in the .csv file included in the upload. We can add a column
+later for the Outlook shortcodes where they aren't the same as the SITKA
+shortcodes.
+
+Directory for uploads:
+sitka/
+
+Submission timestamp:
+$(date -uR -d "$t2")
+
+Generation timestamp:
+$(date -uR -d "$t1")
+
+Submission method:
+FTP
+
+Compressed sizes in bytes:
+$(head -n2 *stats | awk '/.marc.bz2$/{print $9,$5}')
+
+Uncompressed size in bytes:
+$(head -n2 *stats | awk '/.marc$/{print $9,$5}')
+$(find -name '*.csv' -printf '%f %s\n')
+
+Number of records submitted:
+$(grep -h Filename -A5 $i *stats | awk '/.marc$/{print $3,$1}')
+
+SHA1 checksums:
+$(egrep '^[a-f0-9]{32}' *stats -h |sort -k +2)
+$(sha1sum *.csv)
+EOF
diff --git a/marc_export_custom/stats.pl b/marc_export_custom/stats.pl
new file mode 100755 (executable)
index 0000000..b8e53f8
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+use MARC::Batch;
+use strict;
+use warnings;
+my $batch = MARC::Batch->new( 'USMARC', @ARGV );
+$batch->strict_off();
+$batch->warnings_off();
+my $count_raw = 0;
+my $count_901c = 0;
+while ( my $marc = $batch->next ) {
+    $count_raw++;
+    my $field_901c = $marc->subfield(901,"c");
+    if(defined $field_901c) {
+       chomp $field_901c;
+       $count_901c++ if ($field_901c =~ /^.+$/);
+    }
+}
+printf "Count (raw): %d\n",$count_raw;
+printf "Count (901c): %d\n",$count_901c;
diff --git a/marc_export_custom/stats.sh b/marc_export_custom/stats.sh
new file mode 100755 (executable)
index 0000000..82e53ba
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash
+files=$(ls *.marc.bz2 *.marc 2>/dev/null |grep -v split |sed 's,.bz2,,g')
+for i in $files; do 
+       s=$i.stats
+       j=$i.bz2
+       [ -f $s ] && continue
+       echo === $i
+       if [ -f $j -a ! -f $i ]; then
+               bunzip2 -k $j
+       fi
+       if [ -f $i -a ! -f $j ]; then
+               pbzip2 -9kv -p4 $i
+       fi
+       if [ ! -f $i -o ! -f $j ]; then
+               echo "Missing $i or $j"
+               continue
+       fi
+       ls -la $i $j | tee $s
+       sha1sum $i $j | tee -a $s
+       marcdump --stats --quiet --noprint $i | tee -a ${s}
+       rm -f $i
+done
diff --git a/marc_export_custom/upload.lftp b/marc_export_custom/upload.lftp
new file mode 100755 (executable)
index 0000000..f616840
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/lftp
+open ftp://ftpbcuc:bcv15c@ftp.auto-graphics.com/
+mkdir -p sitka
+cd sitka
+mput *csv *stats
+mput *bz2
+rels -l