install-eg.sh: fix setup of non-prod Apache includes
[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))
d10c96dc 5NAME=outlook
55318b37
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
e404bb37 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)
e404bb37 14cd $OUTDIR
5e85b8ab 15echo Prep $(date -uR)/@$(date +%s)
e404bb37
RJ
16$DIR/fetch-shortcodes.sh
17cd $DIR
5e85b8ab 18echo Exporting $(date -uR)/@$(date +%s)
d10c96dc 19export PERLOPT=-X
ff03d26c 20time ./sitka-full-export-parallel.sh >$OUTDIR/script.log 2>&1
368b2926 21rc=$?
e404bb37
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)
ff03d26c 29DELETE=1 $DIR/stats.sh >$OUTDIR/stats.log 2>&1
619e205d 30# Look for zeros in the output marc
d10c96dc 31echo Sanity $(date -uR)/@$(date +%s)
619e205d 32egrep -vsq '^([[:space:]]*0){2}.*marc$' *stats
368b2926 33grep_result=$?
619e205d 34# halt if found
368b2926 35if [ $rc -ne 0 -o $grep_result -ne 0 ]; then
619e205d 36 echo "Failed to run export! Human needed! export=$rc grep_sanity=$grep_result" 1>&2
368b2926
RJ
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
44FTPSITE=ftp://ftpbcuc:bcv15c@ftp.auto-graphics.com/
45FTPDIR=sitka/$T
e404bb37 46cat >lftp.cmd <<EOF
d10c96dc
RJ
47open $FTPSITE
48mkdir -p $FTPDIR
49cd $FTPDIR
e404bb37
RJ
50mput *csv *stats
51mput *bz2
52rels -l
53EOF
54lftp -f lftp.cmd
5e85b8ab 55echo Email $(date -uR)/@$(date +%s)
d10c96dc
RJ
56cp $DIR/email-template-${NAME}.sh $OUTDIR/
57chmod +x email-template-${NAME}.sh
58./email-template-${NAME}.sh "$T" "@$(date +%s)" >email.txt
59/usr/lib/sendmail -t -f sysop@bc.libraries.coop <email.txt