Refactor export scripts and take my email address off them.
[sitka/sitka-tools.git] / marc_export_custom / mucn-full-export-parallel-ebsco-wrapper.sh
CommitLineData
e11c7cc6
RJ
1#!/bin/bash
2# This is meant to be fire-and-forget
3# Only use it if you trust the output!
4export DIR=$(readlink -f $(dirname $0))
d10c96dc 5NAME=ebsco
e11c7cc6
RJ
6if [ -z "${MAKEOPTS}" ]; then
7 echo "MAKEOPTS env variable is not set"
8 echo "If you really want this to be serialized, export MAKEOPTS=-j1"
9 echo "Otherwise set it about 1.5x your number of CPUs!"
10 exit 1
11fi
12[ -z "${T}" ] && export T=$(date -u +%Y%m%dT%H%M%SZ)
d10c96dc 13[ -z "${OUTDIR}" ] && export OUTDIR=$(mktemp --tmpdir -d ${NAME}_export.$T.XXXXXXX)
e11c7cc6 14cd $OUTDIR
5e85b8ab 15echo Prep $(date -uR)/@$(date +%s)
e11c7cc6
RJ
16$DIR/fetch-shortcodes.sh
17cd $DIR
5e85b8ab 18echo Exporting $(date -uR)/@$(date +%s)
e270fa90 19export PERLOPT=-X
d10c96dc
RJ
20time ./mucn-${NAME}-full-export-parallel.sh >script.log 2>&1
21rc=$?
e11c7cc6
RJ
22cd $OUTDIR
23mkdir split
24mv *split* split/
5e85b8ab 25echo Compressing $(date -uR)/@$(date +%s)
2ec1922a
RJ
26pbzip2 -9nk -p4 *{marc,log}
27pbzip2 -9n -p4 split/*{marc,log}
5e85b8ab 28echo Stats $(date -uR)/@$(date +%s)
d10c96dc 29DELETE=0 $DIR/stats.sh >stats.log 2>&1
2ec1922a 30# Look for zeros in the output marc
5e85b8ab 31echo Sanity $(date -uR)/@$(date +%s)
2ec1922a
RJ
32egrep -vsq '^([[:space:]]*0){2}.*marc$' *stats
33grep_result=$?
34# halt if found
35if [ $rc -ne 0 -o $grep_result -ne 0 ]; then
36 echo "Failed to run export! Human needed! export=$rc grep_sanity=$grep_result" 1>&2
37 cat *stats 1>&2
38 exit 1
39fi
5e85b8ab 40echo FTP $(date -uR)/@$(date +%s)
2ec1922a
RJ
41# Two passes with mget, so the stats and csv are always there first
42# they are small and serve to show we might be uploading more, and they have
43# checksums so AutoGraphics can check the upload
d10c96dc
RJ
44# EBSCO wants the raw .marc, they do not support any compression
45FTPSITE=ftp://cat00975a:neJUJ4ez@ftp.epnet.com/
8dad87fc 46FTPDIR=full/mucn/$T
e11c7cc6 47cat >lftp.cmd <<EOF
d10c96dc 48open $FTPSITE
8dad87fc
RJ
49mkdir -p $FTPDIR
50cd $FTPDIR
e11c7cc6 51mput *csv *stats
8dad87fc 52mput *bz2 *marc
e11c7cc6
RJ
53rels -l
54EOF
55lftp -f lftp.cmd
5e85b8ab 56echo Email $(date -uR)/@$(date +%s)
d10c96dc
RJ
57cp $DIR/email-template-${NAME}.sh $OUTDIR/
58chmod +x email-template-${NAME}.sh
59./email-template-${NAME}.sh "$T" "@$(date +%s)" >email.txt
60/usr/lib/sendmail -t -f sysop@bc.libraries.coop <email.txt