# 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
+
--- /dev/null
+#!/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
+
+