Fix grep fail.
[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
e5fb4602 16export PERLOPT=-X
e404bb37 17time ./sitka-full-export-parallel.sh
368b2926 18rc=$?
e404bb37
RJ
19cd $OUTDIR
20mkdir split
21mv *split* split/
22pbzip2 -9nvk -p4 *{marc,log}
23pbzip2 -9nv -p4 split/*{marc,log}
24$DIR/stats.sh
619e205d
RJ
25# Look for zeros in the output marc
26egrep -vsq '^([[:space:]]*0){2}.*marc$' *stats
368b2926 27grep_result=$?
619e205d 28# halt if found
368b2926 29if [ $rc -ne 0 -o $grep_result -ne 0 ]; then
619e205d 30 echo "Failed to run export! Human needed! export=$rc grep_sanity=$grep_result" 1>&2
368b2926
RJ
31 cat *stats 1>&2
32 exit 1
33fi
d8966f59 34cp $DIR/email-template-outlook.sh $OUTDIR/
e404bb37
RJ
35cat >lftp.cmd <<EOF
36open ftp://ftpbcuc:bcv15c@ftp.auto-graphics.com/
37mkdir -p sitka/$T
38cd sitka/$T
39mput *csv *stats
40mput *bz2
41rels -l
42EOF
43lftp -f lftp.cmd
d8966f59
RJ
44chmod +x email-template-outlook.sh
45./email-template-outlook.sh "$T" "@$(date +%s)" >email.txt
d1bc237c 46/usr/lib/sendmail -f rjohnson@sitka.bclibraries.ca <email.txt