Improve error checking before export actually triggers the FTP upload.
[sitka/sitka-tools.git] / marc_export_custom / sitka-full-export-parallel-outlook-wrapper.sh
CommitLineData
e404bb37
RJ
1#!/bin/bash
2# This is meant to be fire-and-forget
3# Only use it if you trust the output!
e38e56a8 4export DIR=$(readlink -f $(dirname $0))
55318b37
RJ
5if [ -z "${MAKEOPTS}" ]; then
6 echo "MAKEOPTS env variable is not set"
7 echo "If you really want this to be serialized, export MAKEOPTS=-j1"
8 echo "Otherwise set it about 1.5x your number of CPUs!"
9 exit 1
10fi
e404bb37 11[ -z "${T}" ] && export T=$(date -u +%Y%m%dT%H%M%SZ)
d1bc237c 12[ -z "${OUTDIR}" ] && export OUTDIR=$(mktemp --tmpdir -d outlook_export.$T.XXXXXXX)
e404bb37
RJ
13cd $OUTDIR
14$DIR/fetch-shortcodes.sh
15cd $DIR
16time ./sitka-full-export-parallel.sh
368b2926 17rc=$?
e404bb37
RJ
18cd $OUTDIR
19mkdir split
20mv *split* split/
21pbzip2 -9nvk -p4 *{marc,log}
22pbzip2 -9nv -p4 split/*{marc,log}
23$DIR/stats.sh
368b2926
RJ
24egrep -sq '^([[:space:]]*0){2}' *stats
25grep_result=$?
26if [ $rc -ne 0 -o $grep_result -ne 0 ]; then
27 echo "Failed to run export! Human needed! export=$rc grep=$rc" 1>&2
28 cat *stats 1>&2
29 exit 1
30fi
d8966f59 31cp $DIR/email-template-outlook.sh $OUTDIR/
e404bb37
RJ
32cat >lftp.cmd <<EOF
33open ftp://ftpbcuc:bcv15c@ftp.auto-graphics.com/
34mkdir -p sitka/$T
35cd sitka/$T
36mput *csv *stats
37mput *bz2
38rels -l
39EOF
40lftp -f lftp.cmd
d8966f59
RJ
41chmod +x email-template-outlook.sh
42./email-template-outlook.sh "$T" "@$(date +%s)" >email.txt
d1bc237c 43/usr/lib/sendmail -f rjohnson@sitka.bclibraries.ca <email.txt