diff --git a/bin/lib/logging.sh b/bin/lib/logging.sh index 1942092..4b6369f 100644 --- a/bin/lib/logging.sh +++ b/bin/lib/logging.sh @@ -5,6 +5,8 @@ trap 'exit 1' HUP INT QUIT TERM +trap 'on_error' EXIT + log::prefix() { date=$(gdate '+%Y-%m-%d %H:%M:%S,%3N') printf '%s %s\n' "${date}" "${*}" @@ -31,11 +33,13 @@ log::error() { } log::fatal() { - reason='Unknown or not specified' - if [ "$1" ]; then - reason=$1 - fi + reason="${1-Unknown or not specified}" log::error "Fatal error. Reason: ${reason}" kill -s TERM $$ } +on_error() { + if [ $? -ne 0 ]; then + log::fatal "Unhandled script failure" + fi +} diff --git a/bin/ul11u4_gate_open.sh b/bin/ul11u4_gate_open.sh index 327f5e9..1057d5d 100755 --- a/bin/ul11u4_gate_open.sh +++ b/bin/ul11u4_gate_open.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -# shellcheck disable=SC1091,SC2015 - [[ "$0" == /* ]] && typeset -r PRG=$0 || typeset -r PRG=$PWD/$0 BINDIR=$(dirname "$PRG") @@ -9,14 +7,21 @@ typeset -r BINDIR source "${BINDIR}/lib/logging.sh" -TARGET=$1 +TARGET="${1-11.4.81.0.1.195.1}" + +URL="http://grt.us.oracle.com/grt/webservice/grtList/?gate=20&show=All&gateName=S11.4-SRU&status=1&target=${TARGET}" +out=$(w3m "$URL" -M -cols 400 -graph -dump | awk '/^Details/ {found=1; next} found && NF') -if [ -z "$TARGET" ]; +if [[ -z "$out" ]]; then - log::fatal "No target specified on command line" + log::info "There are no queued RTIs for \"${TARGET}\". Nothing to do..." + exit 0 fi + +log::info "Opening the gate for ${TARGET}" + log::debug "Starting gate open for Ul11u4SRU" log::debug "Target: \"${TARGET}\""