From 98fafe997d4c248ee7f25fb65803763087234aec Mon Sep 17 00:00:00 2001 From: Chris Sharp Date: Thu, 1 Feb 2018 17:39:16 -0500 Subject: [PATCH] Adding pines-finder server scripts --- helper-scripts/get_hold_history.sh | 118 ------------------- pines-finder/auditor_actor_usr_history.sh | 104 +++++++++++++++++ pines-finder/auditor_asset_copy_history.sh | 121 ++++++++++++++++++++ pines-finder/custom_perms_per_user.sh | 67 +++++++++++ pines-finder/find_at_email_notifications.sh | 86 ++++++++++++++ pines-finder/find_at_hold_notifications.sh | 72 ++++++++++++ pines-finder/find_at_pmc_notifications.sh | 77 +++++++++++++ pines-finder/find_at_sms_notifications.sh | 75 ++++++++++++ pines-finder/generate_user_checkout_history.sh | 70 ++++++++++++ pines-finder/get_active_library_count.sh | 5 + pines-finder/get_active_library_list.sh | 5 + pines-finder/get_active_library_list_with_ids.sh | 5 + pines-finder/get_billing_history.sh | 100 ++++++++++++++++ .../get_circ_history.sh | 29 +++-- .../get_combined_perms_per_profile.sh | 7 +- pines-finder/get_email_logs.sh | 67 +++++++++++ pines-finder/get_hold_history.sh | 126 +++++++++++++++++++++ pines-finder/get_reports_template_ids.sh | 43 +++++++ pines-finder/get_transit_history.sh | 78 +++++++++++++ pines-finder/pg_config | 11 ++ pines-finder/predue_lookup.sh | 77 +++++++++++++ pines-finder/run_sql_script.sh | 8 ++ pines-finder/sip_account_lookup.sh | 20 ++++ 23 files changed, 1239 insertions(+), 132 deletions(-) delete mode 100755 helper-scripts/get_hold_history.sh create mode 100755 pines-finder/auditor_actor_usr_history.sh create mode 100755 pines-finder/auditor_asset_copy_history.sh create mode 100755 pines-finder/custom_perms_per_user.sh create mode 100755 pines-finder/find_at_email_notifications.sh create mode 100755 pines-finder/find_at_hold_notifications.sh create mode 100755 pines-finder/find_at_pmc_notifications.sh create mode 100755 pines-finder/find_at_sms_notifications.sh create mode 100755 pines-finder/generate_user_checkout_history.sh create mode 100755 pines-finder/get_active_library_count.sh create mode 100755 pines-finder/get_active_library_list.sh create mode 100755 pines-finder/get_active_library_list_with_ids.sh create mode 100755 pines-finder/get_billing_history.sh rename {helper-scripts => pines-finder}/get_circ_history.sh (80%) rename {helper-scripts => pines-finder}/get_combined_perms_per_profile.sh (81%) create mode 100755 pines-finder/get_email_logs.sh create mode 100755 pines-finder/get_hold_history.sh create mode 100755 pines-finder/get_reports_template_ids.sh create mode 100755 pines-finder/get_transit_history.sh create mode 100644 pines-finder/pg_config create mode 100755 pines-finder/predue_lookup.sh create mode 100755 pines-finder/run_sql_script.sh create mode 100755 pines-finder/sip_account_lookup.sh diff --git a/helper-scripts/get_hold_history.sh b/helper-scripts/get_hold_history.sh deleted file mode 100755 index ff3ca15..0000000 --- a/helper-scripts/get_hold_history.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash - -Usage () { -echo -echo "Usage: $0 [-i item barcode] [-u user_barcode ] [-l result limit]" -echo -echo "If you don't specify item or user barcode, you'll be prompted" -echo "to provide them. 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_HOST="mydbhost" -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 h_usr_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 h_usr_card.barcode = '$USER_BARCODE' AND cp.barcode = '$ITEM_BARCODE'" -fi - -if [ -z "$LIMIT" ]; then - LIMIT=10 -fi - -read -d '' SQL <" +echo +echo "Select one of -b for billings or -p for payments, or neither for a summary." +echo " means the billable transaction ID (circulation or grocery)" +echo "-f creates a file from the result." +echo +} + +while getopts i:sfhbp OPTIONS +do case "$OPTIONS" in + i) XACT_ID="$OPTARG";; + b) BILLINGS=1;; + p) PAYMENTS=1;; + f) EXPORT_FILE=1;; + h) Usage; exit 1;; + esac +done + +PG_CONFIG="pg_config" +source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1; + +# if we have no command line arguments, or both billings and payments selected, exit the script +if [ ! -z "$BILLINGS" ] && [ ! -z "$PAYMENTS" ]; then +echo "Choose /either/ -b or -p, not both." +Usage; exit 1 +elif [ -z "$XACT_ID" ]; then +echo "Bill ID is required." +Usage; exit 1 +fi + +# if we have billings selected... +if [ ! -z "$BILLINGS" ]; then +FILENAME_PREFIX=${XACT_ID}_billing_lineitems__ +read -d '' SQL < ~/${USER_BARCODE}_preminder_logs_${NOTICE_DATE}.txt +EOF +scp $LOG_USER@$LOG_HOST:~/${USER_BARCODE}_preminder_logs_${NOTICE_DATE}.txt . +} + +GetEmail +GetLogMessages diff --git a/pines-finder/get_hold_history.sh b/pines-finder/get_hold_history.sh new file mode 100755 index 0000000..ad0b873 --- /dev/null +++ b/pines-finder/get_hold_history.sh @@ -0,0 +1,126 @@ +#!/bin/bash + +Usage () { +echo +echo "Usage: $0 [-i item barcode] [-u user barcode] [-s server] [-l result limit] [-f]" +echo +echo "If you don't specify item or user barcode, you'll be prompted" +echo "to provide them. 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";; + s) SERVER="$OPTARG";; + f) EXPORT_FILE=1;; + h) Usage; exit 1;; + esac +done + +PG_CONFIG="pg_config" +source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1; + +if [ "$SERVER" = "test" ]; then +PSQL_HOST="test-db01" +elif [ "$SERVER" = "next" ]; then +PSQL_HOST="next-db01" +fi + +# 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 h_usr_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 h_usr_card.barcode = '$USER_BARCODE' AND cp.barcode = '$ITEM_BARCODE'" +fi + +if [ -z "$LIMIT" ]; then + LIMIT=10 +fi + +read -d '' SQL < ~/${USER_BARCODE}_predue_notice_${NOTICE_DATE}.txt +EOF +scp $UTILITY_USER@$UTILITY_HOST:~/${USER_BARCODE}_predue_notice_${NOTICE_DATE}.txt . +} + +GetLogMessages () { +ssh -T $LOG_USER@$LOG_HOST < ~/${USER_BARCODE}_predue_logs_${NOTICE_DATE}.txt +EOF +scp $LOG_USER@$LOG_HOST:~/${USER_BARCODE}_predue_logs_${NOTICE_DATE}.txt . +} + +GetEmail +GetPreminderNotice +GetLogMessages diff --git a/pines-finder/run_sql_script.sh b/pines-finder/run_sql_script.sh new file mode 100755 index 0000000..deec3c9 --- /dev/null +++ b/pines-finder/run_sql_script.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +SCRIPT="$1" +PSQL="/usr/bin/psql" +DB_USER="mydbuser" +DB_HOST="mydb" + +$PSQL -U $DB_USER -h $DB_HOST -1 -f $SCRIPT diff --git a/pines-finder/sip_account_lookup.sh b/pines-finder/sip_account_lookup.sh new file mode 100755 index 0000000..24db7c7 --- /dev/null +++ b/pines-finder/sip_account_lookup.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +Usage () { + echo "$0 sip_username" + exit 1; +} + +SSH_USER="myuser" +SIP_SERVER="sipserver" +SIP_CONFIG="/openils/conf/oils_sip.xml" +USERNAME="$1" + +while getopts u:h OPTIONS + do case "$OPTIONS" in + u) USERNAME="$OPTARG";; + h) Usage; exit 1;; + esac +done + +ssh $SSH_USER@$SIP_SERVER "grep $USERNAME $SIP_CONFIG" -- 2.11.0