JBAS-1919 UMS monthly user balance export script/cron
authorBill Erickson <berickxx@gmail.com>
Fri, 10 Nov 2017 16:51:23 +0000 (11:51 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Generate a monthly user balance export for retrieval by UMS.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/utility-scripts/CRONTAB
KCLS/utility-scripts/ums_user_balances/ums_user_balances.sh [new file with mode: 0755]

index 31d5731..77ca08d 100644 (file)
@@ -166,3 +166,6 @@ BACKSTAGE_PASSWORD = BSPASS
 # Process and archive student import files each Sunday night at 11pm
 # 0 23 * * 0 cd /home/opensrf/Evergreen/KCLS/utility-scripts/import_students && ./sftp-client-agent.sh -b db01 -p -a
 
+# Monthly UMS user balance summary export
+0 3 1 * * . ~/.bashrc && cd $SCRIPT_DIR/ums_user_balances/ && ./ums_user_balances.sh
+
diff --git a/KCLS/utility-scripts/ums_user_balances/ums_user_balances.sh b/KCLS/utility-scripts/ums_user_balances/ums_user_balances.sh
new file mode 100755 (executable)
index 0000000..1b949c8
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+PASSFILE="$HOME/.eg-admin-pass"
+AUTHTOKEN=""
+TODAY=$(date +'%F');
+NOTIFY_EMAIL="bserickson@kcls.org"
+LOGFILE="/openils/var/log/ums_user_balances.log"
+
+function set_auth_token() {
+
+    if [ ! -f $PASSFILE ]; then
+        echo "Admin password file '$PASSFILE' required!"
+        exit 1;
+    fi;
+
+    PASSWORD=$(cat $PASSFILE);
+
+    AUTHTOKEN=$(
+        echo "login admin $PASSWORD" | /openils/bin/srfsh \
+            | grep "Login Session:" | cut -d' ' -f3 | cut -d'.' -f1
+    );
+
+    #echo "Authtoken acquired: $AUTHTOKEN"
+}
+
+set_auth_token;
+
+# Build the request piecemeal for readability
+PARAMS="{\"location\":\"KCLS\",\"start_date\":\"1900-01-01\",\"end_date\":\"$TODAY\"}";
+REQUEST="request open-ils.collections open-ils.collections.user_balance_summary.generate" 
+
+echo "$REQUEST \"$AUTHTOKEN\", $PARAMS" | /openils/bin/srfsh > "$LOGFILE"
+
+if [ -n "$EG_UTIL_NOTIFY" ]; then
+    cat "$LOGFILE" | mailx -s \
+        "UMS Monthly [$TODAY] User Balance Export Started" $NOTIFY_EMAIL
+fi
+
+