From 9f0e2c1fbbc7bec8506a6ec71715d18db35ad0aa Mon Sep 17 00:00:00 2001 From: Sakib Rahman Date: Sun, 9 Jul 2023 03:52:43 -0500 Subject: [PATCH] Create update_monitor_maria_db.sh Script to collect info from condor queue and populate a mysql database that will be updated at regular intervals --- scripts/update_monitor_maria_db.sh | 111 +++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 scripts/update_monitor_maria_db.sh diff --git a/scripts/update_monitor_maria_db.sh b/scripts/update_monitor_maria_db.sh new file mode 100644 index 0000000..8e79c3d --- /dev/null +++ b/scripts/update_monitor_maria_db.sh @@ -0,0 +1,111 @@ +#!/bin/bash +set -Euo pipefail +trap 's=$?; echo "$0: Error on line $LINENO: $BASH_COMMAND"; exit $s' ERR +IFS=$'\n\t' + +# Startup +date + +process_options() { + verbose=false + server="" + user="" + database="" + table="" + + while getopts "hv:s:u:d:t:" opt; do + case $opt in + h) + echo "Usage: $0 -s -u -d -t " + echo "Collect condor queue info and update job monitoring database." + echo "Options:" + echo " -h Help" + echo " -v Verbose level [true/false], default: false" + echo " -s Server name" + echo " -u User name" + echo " -d Database name" + echo " -t Table name" + exit 0 + ;; + v) + verbose=${OPTARG} + ;; + s) + server=${OPTARG} + ;; + u) + user=${OPTARG} + ;; + d) + database=${OPTARG} + ;; + t) + table=${OPTARG} + ;; + \?) + echo "Use -h to display proper usage" + exit 1 + ;; + esac + done + + echo "Verbose: $verbose" + if [[ -n $server ]] && [[ -n $user ]] && [[ -n $database ]] && [[ -n $table ]]; then + echo "Server: $server" + echo "User: $user" + echo "Database: $database" + echo "Table: $table" + else + echo "All required arguments not defined." + echo "Use -h to display proper usage" + exit 1 + fi +} + +collect_job_ids() { + # Run the condor_q command and capture the output + output=$(condor_q --nobatch) + + # Extract the ID column and store it in an array + readarray -t ids < <(echo "$output" | awk '{a[NR]=$1} END{for (i=5; i