Backstage quarterly bib export count email
authorBill Erickson <berickxx@gmail.com>
Mon, 17 Jul 2017 19:15:31 +0000 (15:15 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Send an email after the quarterly bib export file has been generated and
uploaded with the count of bib records in the file.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/authority-control/backstage/backstage-agent.sh

index 029a97a..8fd98c5 100755 (executable)
@@ -33,6 +33,8 @@ CUR_YEAR4=$(date +'%Y')
 CUR_QTR=$(( ($(date +%-m)-1)/3+1 ))
 PREV_QTR_START_DATE=""
 PREV_QTR_END_DATE=""
+# email Bill Erickson and Sally Smith with quarterly bib export totals
+EMAIL_RECIP=bserickson@kcls.org,ssmith@kcls.org
 
 function die { echo "$@" 1>&2 ; exit 1; } # thanks, internet.
 
@@ -169,6 +171,12 @@ function bs_export_qtrly_bibs {
             # Put a file into the working directory with the export 
             # date so the importer can refer to it later.
             echo "$(date +'%F')" > "$WORKING_DIR/EXPORT_DATE"
+
+            # count the number of MARC record separator characters
+            count=$(cat $EXPORT_FILE | perl -e '$/="\x1D";$c = 0;$c++ while (<>);print "$c";')
+            echo "" | mailx -s \
+                "Exported $count Bibs for Backstage Q$CUR_QTR $CUR_YEAR4" \
+                $EMAIL_RECIP
         fi
     else 
         die "No MARC export file was created at $EXPORT_FILE"