Commit | Line | Data |
---|---|---|
e404bb37 RJ |
1 | #!/bin/bash |
2 | # This is meant to be fire-and-forget | |
3 | # Only use it if you trust the output! | |
e38e56a8 | 4 | export DIR=$(readlink -f $(dirname $0)) |
55318b37 RJ |
5 | if [ -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 | |
10 | fi | |
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 | 13 | cd $OUTDIR |
5e85b8ab | 14 | echo Prep $(date -uR)/@$(date +%s) |
e404bb37 RJ |
15 | $DIR/fetch-shortcodes.sh |
16 | cd $DIR | |
e5fb4602 | 17 | export PERLOPT=-X |
5e85b8ab | 18 | echo Exporting $(date -uR)/@$(date +%s) |
e404bb37 | 19 | time ./sitka-full-export-parallel.sh |
368b2926 | 20 | rc=$? |
e404bb37 RJ |
21 | cd $OUTDIR |
22 | mkdir split | |
23 | mv *split* split/ | |
5e85b8ab | 24 | echo Compressing $(date -uR)/@$(date +%s) |
2ec1922a RJ |
25 | pbzip2 -9nk -p4 *{marc,log} |
26 | pbzip2 -9n -p4 split/*{marc,log} | |
5e85b8ab | 27 | echo Stats $(date -uR)/@$(date +%s) |
e404bb37 | 28 | $DIR/stats.sh |
5e85b8ab | 29 | echo Sanity $(date -uR)/@$(date +%s) |
619e205d RJ |
30 | # Look for zeros in the output marc |
31 | egrep -vsq '^([[:space:]]*0){2}.*marc$' *stats | |
368b2926 | 32 | grep_result=$? |
619e205d | 33 | # halt if found |
368b2926 | 34 | if [ $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 | |
38 | fi | |
5e85b8ab | 39 | echo 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 |
43 | cat >lftp.cmd <<EOF |
44 | open ftp://ftpbcuc:bcv15c@ftp.auto-graphics.com/ | |
45 | mkdir -p sitka/$T | |
46 | cd sitka/$T | |
47 | mput *csv *stats | |
48 | mput *bz2 | |
49 | rels -l | |
50 | EOF | |
51 | lftp -f lftp.cmd | |
5e85b8ab | 52 | echo Email $(date -uR)/@$(date +%s) |
2ec1922a | 53 | cp $DIR/email-template-outlook.sh $OUTDIR/ |
d8966f59 RJ |
54 | chmod +x email-template-outlook.sh |
55 | ./email-template-outlook.sh "$T" "@$(date +%s)" >email.txt | |
2620278f | 56 | /usr/lib/sendmail -t -f rjohnson@sitka.bclibraries.ca <email.txt |