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)) |
d10c96dc | 5 | NAME=outlook |
55318b37 RJ |
6 | if [ -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 | |
11 | fi | |
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 | 14 | cd $OUTDIR |
5e85b8ab | 15 | echo Prep $(date -uR)/@$(date +%s) |
e404bb37 RJ |
16 | $DIR/fetch-shortcodes.sh |
17 | cd $DIR | |
5e85b8ab | 18 | echo Exporting $(date -uR)/@$(date +%s) |
d10c96dc RJ |
19 | export PERLOPT=-X |
20 | time ./sitka-full-export-parallel.sh >script.log 2>&1 | |
368b2926 | 21 | rc=$? |
e404bb37 RJ |
22 | cd $OUTDIR |
23 | mkdir split | |
24 | mv *split* split/ | |
5e85b8ab | 25 | echo Compressing $(date -uR)/@$(date +%s) |
2ec1922a RJ |
26 | pbzip2 -9nk -p4 *{marc,log} |
27 | pbzip2 -9n -p4 split/*{marc,log} | |
5e85b8ab | 28 | echo Stats $(date -uR)/@$(date +%s) |
d10c96dc | 29 | DELETE=1 $DIR/stats.sh >stats.log 2>&1 |
619e205d | 30 | # Look for zeros in the output marc |
d10c96dc | 31 | echo Sanity $(date -uR)/@$(date +%s) |
619e205d | 32 | egrep -vsq '^([[:space:]]*0){2}.*marc$' *stats |
368b2926 | 33 | grep_result=$? |
619e205d | 34 | # halt if found |
368b2926 | 35 | if [ $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 | |
39 | fi | |
5e85b8ab | 40 | echo 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 |
44 | FTPSITE=ftp://ftpbcuc:bcv15c@ftp.auto-graphics.com/ |
45 | FTPDIR=sitka/$T | |
e404bb37 | 46 | cat >lftp.cmd <<EOF |
d10c96dc RJ |
47 | open $FTPSITE |
48 | mkdir -p $FTPDIR | |
49 | cd $FTPDIR | |
e404bb37 RJ |
50 | mput *csv *stats |
51 | mput *bz2 | |
52 | rels -l | |
53 | EOF | |
54 | lftp -f lftp.cmd | |
5e85b8ab | 55 | echo Email $(date -uR)/@$(date +%s) |
d10c96dc RJ |
56 | cp $DIR/email-template-${NAME}.sh $OUTDIR/ |
57 | chmod +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 |