From: Chris Sharp Date: Mon, 19 Oct 2015 15:46:47 +0000 (-0400) Subject: adding circ and hold history query scripts X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6d31c903a80d358565e92ca04878110507c04946;p=contrib%2Fpines.git adding circ and hold history query scripts --- diff --git a/get_circ_history.sh b/get_circ_history.sh new file mode 100755 index 0000000..4cba791 --- /dev/null +++ b/get_circ_history.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +Usage () { +echo +echo "Usage: $0 [-b item barcode] [-l result limit]" +echo +echo "If you don't specify item barcode, you'll be prompted" +echo "to provide one. Result limit defaults to 10." +echo +} + +while getopts i:l:u:h OPTIONS +do case "$OPTIONS" in + i) ITEM_BARCODE="$OPTARG";; # TODO: allow multiple barcodes + l) LIMIT="$OPTARG";; + u) USER_BARCODE="$OPTARG";; + h) Usage; exit 1;; + esac +done + +# Note: it is assumed that you're using .pgpass here +PSQL="/usr/bin/psql" +PSQL_USER="evergreen" +PSQL_DB="evergreen" + +# if we have no command line arguments, prompt the user +if [ "$*" = '' ]; then + echo "We need an item barcode and/or a user barcode." + read -p "Please enter the item barcode (Enter for none): " ITEM_BARCODE + read -p "Please enter the user barcode (Enter for none): " USER_BARCODE +fi + +# if we have a user barcode but no item barcode... +if [ -z "$ITEM_BARCODE" ] && [ ! -z "$USER_BARCODE" ]; then + SQL_WHERE="WHERE u_card.barcode = '$USER_BARCODE'" +# if we have an item barcode but no user barcode... +elif [ ! -z "$ITEM_BARCODE" ] && [ -z "$USER_BARCODE" ]; then + SQL_WHERE="WHERE cp.barcode = '$ITEM_BARCODE'" +# both are empty, exit the script +elif [ -z "$ITEM_BARCODE" ] && [ -z "$USER_BARCODE" ]; then + echo "We need either an item or user barcode to run this script. Exiting..." + exit 1; +# if we've gotten this far, we have both +else + SQL_WHERE="WHERE u_card.barcode = '$USER_BARCODE' AND cp.barcode = '$ITEM_BARCODE'" +fi + +if [ -z "$LIMIT" ]; then + LIMIT=10 +fi + +read -d '' SQL <