Fix syntax.
[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 13cd $OUTDIR
5e85b8ab 14echo Prep $(date -uR)/@$(date +%s)
e404bb37
RJ
15$DIR/fetch-shortcodes.sh
16cd $DIR
e5fb4602 17export PERLOPT=-X
5e85b8ab 18echo Exporting $(date -uR)/@$(date +%s)
e404bb37 19time ./sitka-full-export-parallel.sh
368b2926 20rc=$?
e404bb37
RJ
21cd $OUTDIR
22mkdir split
23mv *split* split/
5e85b8ab 24echo Compressing $(date -uR)/@$(date +%s)
2ec1922a
RJ
25pbzip2 -9nk -p4 *{marc,log}
26pbzip2 -9n -p4 split/*{marc,log}
5e85b8ab 27echo Stats $(date -uR)/@$(date +%s)
e404bb37 28$DIR/stats.sh
5e85b8ab 29echo Sanity $(date -uR)/@$(date +%s)
619e205d
RJ
30# Look for zeros in the output marc
31egrep -vsq '^([[:space:]]*0){2}.*marc$' *stats
368b2926 32grep_result=$?
619e205d 33# halt if found
368b2926 34if [ $rc -ne 0 -o $grep_result -ne 0 ]; then
619e205d 35 echo "Failed to run export! Human needed! export=$rc grep_sanity=$grep_result" 1>&2
368b2926
RJ
36 cat *stats 1>&2
37 exit 1
38fi
5e85b8ab 39echo FTP $(date -uR)/@$(date +%s)
2ec1922a
RJ
40# Two passes with mget, so the stats and csv are always there first
41# they are small and serve to show we might be uploading more, and they have
42# checksums so AutoGraphics can check the upload
e404bb37
RJ
43cat >lftp.cmd <<EOF
44open ftp://ftpbcuc:bcv15c@ftp.auto-graphics.com/
45mkdir -p sitka/$T
46cd sitka/$T
47mput *csv *stats
48mput *bz2
49rels -l
50EOF
51lftp -f lftp.cmd
5e85b8ab 52echo Email $(date -uR)/@$(date +%s)
2ec1922a 53cp $DIR/email-template-outlook.sh $OUTDIR/
d8966f59
RJ
54chmod +x email-template-outlook.sh
55./email-template-outlook.sh "$T" "@$(date +%s)" >email.txt
d1bc237c 56/usr/lib/sendmail -f rjohnson@sitka.bclibraries.ca <email.txt