From 90bc3267aec3d0f405819969fee349227b4a17c9 Mon Sep 17 00:00:00 2001 From: ajshedivy Date: Mon, 20 Feb 2023 15:48:30 -0600 Subject: [PATCH 1/4] add sctail file --- scripts/sctail | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 scripts/sctail diff --git a/scripts/sctail b/scripts/sctail new file mode 100755 index 0000000..77395fd --- /dev/null +++ b/scripts/sctail @@ -0,0 +1,9 @@ +#!/QOpenSys/pkgs/bin/bash +FILE_NAME=$($(dirname $0)/sc loginfo $1) +if [ -z "$FILE_NAME" ] +then + >&2 echo "No configuration file found for '$1'" + exit 5 +fi + +echo "Configuration for '$1' found at $FILE_NAME" From d9f88517235ab6234d3c872d9d8f1aed8128dc73 Mon Sep 17 00:00:00 2001 From: ajshedivy Date: Mon, 20 Feb 2023 17:03:10 -0600 Subject: [PATCH 2/4] edit sctail logic --- scripts/sctail | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/sctail b/scripts/sctail index 77395fd..8d27519 100755 --- a/scripts/sctail +++ b/scripts/sctail @@ -1,9 +1,3 @@ #!/QOpenSys/pkgs/bin/bash -FILE_NAME=$($(dirname $0)/sc loginfo $1) -if [ -z "$FILE_NAME" ] -then - >&2 echo "No configuration file found for '$1'" - exit 5 -fi -echo "Configuration for '$1' found at $FILE_NAME" +/QOpenSys/pkgs/bin/sc loginfo $1 | /QOpenSys/pkgs/bin/cut -d ':' -f 2 | /QOpenSys/pkgs/bin/xargs tail -f From 88edc74a847afaef631b3fadd1dd51ed5a54896c Mon Sep 17 00:00:00 2001 From: ajshedivy Date: Mon, 20 Feb 2023 17:36:15 -0600 Subject: [PATCH 3/4] update sctail logic, update makefile --- Makefile | 1 + scripts/sctail | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b9fda66..5500181 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,7 @@ install: scripts/sc scripts/scinit scripts/sc_install_defaults target/sc.jar tar install -m 555 -o qsys scripts/sc ${INSTALL_ROOT}/QOpenSys/pkgs/bin/ install -m 555 -o qsys scripts/scinit ${INSTALL_ROOT}/QOpenSys/pkgs/bin/ install -m 555 -o qsys scripts/scedit ${INSTALL_ROOT}/QOpenSys/pkgs/bin/ + install -m 555 -o qsys scripts/sctail ${INSTALL_ROOT}/QOpenSys/pkgs/bin/ install -m 555 -o qsys scripts/scopenports ${INSTALL_ROOT}/QOpenSys/pkgs/bin/ install -m 555 -o qsys scripts/sc_install_defaults ${INSTALL_ROOT}/QOpenSys/pkgs/bin/ install -m 444 -o qsys target/sc.jar ${INSTALL_ROOT}/QOpenSys/pkgs/lib/sc/sc.jar diff --git a/scripts/sctail b/scripts/sctail index 8d27519..b908c10 100755 --- a/scripts/sctail +++ b/scripts/sctail @@ -1,3 +1,45 @@ #!/QOpenSys/pkgs/bin/bash -/QOpenSys/pkgs/bin/sc loginfo $1 | /QOpenSys/pkgs/bin/cut -d ':' -f 2 | /QOpenSys/pkgs/bin/xargs tail -f +if (($# == 0)); then + echo "usage: sctail [-f|--follow] " + exit 0 +fi + +POSITIONAL_ARGS=() +HELP_MSG=NO +FOLLOW=NO + +while [[ $# -gt 0 ]]; do + case $1 in + -f|--follow) + FOLLOW=YES + shift # past argument with no value + ;; + --help) + HELP_MSG=YES + shift # past argument with no value + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + *) + POSITIONAL_ARGS+=("$1") # save positional arg + shift # past argument + ;; + esac +done +set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters + +if [ ${HELP_MSG} == YES ]; then + echo "usage: sctail [-f|--follow] " + exit 0 +fi + +/QOpenSys/pkgs/bin/sc loginfo $1 + +if [ ${FOLLOW} == YES ]; then + /QOpenSys/pkgs/bin/sc loginfo $1 | /QOpenSys/pkgs/bin/cut -d ':' -f 2 | /QOpenSys/pkgs/bin/xargs tail -f +else + /QOpenSys/pkgs/bin/sc loginfo $1 | /QOpenSys/pkgs/bin/cut -d ':' -f 2 | /QOpenSys/pkgs/bin/xargs tail +fi From 3f0012f149314b0012bb090357c55eae11b1f22e Mon Sep 17 00:00:00 2001 From: ajshedivy Date: Tue, 21 Feb 2023 10:58:24 -0600 Subject: [PATCH 4/4] formalize tail logic and sc call --- scripts/sctail | 85 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/scripts/sctail b/scripts/sctail index b908c10..1c3e2c5 100755 --- a/scripts/sctail +++ b/scripts/sctail @@ -1,45 +1,92 @@ #!/QOpenSys/pkgs/bin/bash +if [[ "$LC_ALL" != *UTF-8* ]]; then + # LC_ALL is not set. Set it to EN_US.UTF-8 if present + if [ -e /usr/lib/nls/loc/EN_US.UTF-8 ]; then + export LC_ALL=EN_US.UTF-8 + else + # EN_US.UTF-8 is not present. Look for installed UTF-8 locale + INSTALLEDUTF8LOCALE=$(ls -b /usr/lib/nls/loc | grep -E '.UTF-8$' | tail -n 1) + if [[ "" = "$INSTALLEDUTF8LOCALE" ]]; then + >&2 echo "WARNING: Cannot find a UTF-8 locale installed on this system." + else + export LC_ALL=$INSTALLEDUTF8LOCALE + fi + fi +fi + if (($# == 0)); then - echo "usage: sctail [-f|--follow] " + echo "usage: sctail [tail OPTION]... " exit 0 fi -POSITIONAL_ARGS=() HELP_MSG=NO -FOLLOW=NO +# Set the default arguments for tail +TAIL_ARGS="" + +# Initialize variable for service name +SERVICE="" + +# Declare an array to hold the arguments and their values +declare -a ARGS=() + +# Loop through the command line arguments while [[ $# -gt 0 ]]; do - case $1 in - -f|--follow) - FOLLOW=YES - shift # past argument with no value + key="$1" + case $key in + -c|--bytes|-n|--lines|-s|--sleep-interval|--pid|--max-unchanged-stats) + # If the argument has a value, add it to the array + if [[ $# -gt 1 && "$2" != -* ]]; then + ARGS+=("$1 $2") + shift + else + ARGS+=("$1") + fi + ;; + -f|--follow|-F|--retry|-q|--quiet|--silent|-v|--verbose|-z|--zero-terminated|--version) + ARGS+=("$1") ;; --help) HELP_MSG=YES shift # past argument with no value ;; -*|--*) - echo "Unknown option $1" + echo "sctail: invalid option -- '$1'" + echo "usage: sctail [OPTION]... " + echo "Try 'sctail --help' for more information." exit 1 ;; *) - POSITIONAL_ARGS+=("$1") # save positional arg - shift # past argument + + # If the argument doesn't start with a dash, set it as the SERVICE value + SERVICE="$1" ;; esac + shift done -set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters -if [ ${HELP_MSG} == YES ]; then - echo "usage: sctail [-f|--follow] " - exit 0 +if [[ $HELP_MSG == YES ]]; then + echo "sctail usage: sctail [tail OPTION]...