From d04fef5436ac10b1e6f25e5657a4d95c37d74a8a Mon Sep 17 00:00:00 2001 From: Tyler Pennebaker Date: Fri, 11 Mar 2022 12:33:19 -0800 Subject: [PATCH 1/5] ENH: Add host option for ioctool --- scripts/ioctool | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/ioctool b/scripts/ioctool index d5f8b91b..f5d529c9 100755 --- a/scripts/ioctool +++ b/scripts/ioctool @@ -132,4 +132,13 @@ elif [ "$CMD" == "telnet" ]; then # echo "Host no in subnet that connect" echo "$HOST":"$PORT" telnet "$HOST" "$PORT" + + +elif [ "$CMD" == "host" ]; then + INFO=$(grep_ioc "$NAME" all | grep "id:'$NAME'") + if [ -z "$INFO" ]; then + echo "$NAME could not be found. Exiting..." >&2 + exit 1 + fi + echo "$INFO" | sed -n "s/^.*host: '\(\S*\)'.*$/\1/p" fi From b0bbaf56190b6166568049e8826efee75896844b Mon Sep 17 00:00:00 2001 From: Tyler Pennebaker Date: Fri, 11 Mar 2022 13:26:23 -0800 Subject: [PATCH 2/5] Add support for PVs in other hutches --- scripts/serverStat | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/serverStat b/scripts/serverStat index fd989040..ec876661 100755 --- a/scripts/serverStat +++ b/scripts/serverStat @@ -53,21 +53,24 @@ isCam(){ host_from_PV(){ if [[ $NAME == *':'* ]] && [[ $HUTCH == 'unknown_hutch' ]]; then echo 'Getting info for a host of a PV currently only works on the hutch networks' - exit + exit 1 fi if [[ ${NAME:0:3} == "${HUTCH^^}" ]]; then HOST=$(cainfo "$NAME" | grep Host | awk '{print $2}' | awk 'BEGIN { FS = ":"}; {print $1}' | sed s/'.pcdsn'/''/g) if [[ $HOST == *'disconnected'* ]]; then - echo PV "$NAME" is disconnected - exit + echo "PV $NAME is disconnected" + exit 1 fi - echo PV "$NAME" is hosted on server "$HOST" - NAME=$HOST - DEV=$HOST else - echo 'Getting info for a host of a PV currently only works on the hutch network (e.g. for MFX:xxx from the mfx network)' - exit + HOST=$(ioctool $NAME host) + if [[ -z "$HOST" ]]; then + echo "Host can't be found for PV $NAME" + exit 1 + fi fi + echo PV "$NAME" is hosted on server "$HOST" + NAME=$HOST + DEV=$HOST } usage(){ From a98282f300f8123d1de1d9c4610ca0cc9c92bcee Mon Sep 17 00:00:00 2001 From: Tyler Pennebaker Date: Fri, 11 Mar 2022 13:49:25 -0800 Subject: [PATCH 3/5] MNT: Update PATH variable assignments to use current directory first --- scripts/get_curr_exp | 5 ++--- scripts/get_hutch_name | 5 ++--- scripts/get_lastRun | 5 ++--- scripts/imgr | 2 +- scripts/iocmanager | 2 +- scripts/makepeds | 5 ++--- scripts/serverStat | 5 ++--- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/scripts/get_curr_exp b/scripts/get_curr_exp index da2ceeb9..ec601bb8 100755 --- a/scripts/get_curr_exp +++ b/scripts/get_curr_exp @@ -32,9 +32,8 @@ do esac done -DIRTMP=`dirname "${BASH_SOURCE[0]}"` -DIR="$( cd $DIRTMP && pwd -P )" -PATH=$PATH:$DIR +DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")") +PATH=$DIR:$PATH if [ $INSTRUMENT != 'xxx' ]; then CURR_EXP=`get_info --hutch ${INSTRUMENT^^} --exp` diff --git a/scripts/get_hutch_name b/scripts/get_hutch_name index 84a6fa9e..9d15a20b 100755 --- a/scripts/get_hutch_name +++ b/scripts/get_hutch_name @@ -13,9 +13,8 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then exit 0 fi -DIRTMP=`dirname "${BASH_SOURCE[0]}"` -DIR="$( cd $DIRTMP && pwd -P )" -PATH=$PATH:$DIR +DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")") +PATH=$DIR:$PATH hutch=`get_info --gethutch` echo $hutch diff --git a/scripts/get_lastRun b/scripts/get_lastRun index a7442f75..974a8bc0 100755 --- a/scripts/get_lastRun +++ b/scripts/get_lastRun @@ -19,9 +19,8 @@ AskLive=0 Ended=0 INSTRUMENT='xxx' -DIRTMP=`dirname "${BASH_SOURCE[0]}"` -DIR="$( cd $DIRTMP && pwd -P )" -PATH=$PATH:$DIR +DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")") +PATH=$DIR:$PATH while getopts "H:i:le" OPTION do diff --git a/scripts/imgr b/scripts/imgr index aaf6d0fd..4af0c347 100755 --- a/scripts/imgr +++ b/scripts/imgr @@ -32,7 +32,7 @@ fi # Add engineering_tools to PATH for get_hutch_name DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")") -PATH=$PATH:$DIR +PATH=$DIR:$PATH # Search for hutch in args for (( i=1; i<=$#; i++)); do diff --git a/scripts/iocmanager b/scripts/iocmanager index fd8eaf82..a25053ee 100755 --- a/scripts/iocmanager +++ b/scripts/iocmanager @@ -17,7 +17,7 @@ fi # Check hutch DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")") -PATH=$PATH:$DIR +PATH=$DIR:$PATH HUTCH=${1:-$(get_hutch_name)} # Exit if hutch is still unknown diff --git a/scripts/makepeds b/scripts/makepeds index 3cc8891c..e4e621f5 100755 --- a/scripts/makepeds +++ b/scripts/makepeds @@ -1,8 +1,7 @@ #! /bin/bash -DIRTMP=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") -DIR="$( cd $DIRTMP && pwd -P )" -PATH=$PATH:$DIR +DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")") +PATH=$DIR:$PATH usage() { diff --git a/scripts/serverStat b/scripts/serverStat index ec876661..f28f11ff 100755 --- a/scripts/serverStat +++ b/scripts/serverStat @@ -91,9 +91,8 @@ expert : display info and run checks on server EOF } -DIRTMP=$(dirname "${BASH_SOURCE[0]}") -DIR=$( cd "$DIRTMP" && pwd -P ) -PATH=$PATH:$DIR +DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")") +PATH=$DIR:$PATH HUTCH=$(get_hutch_name) for name in "tmo" "rix" "txi" "xpp" "xcs" "mfx" "cxi" "mec" "det"; do From 7bee8128a5e6e190b8bf48e32859675f8a2473d1 Mon Sep 17 00:00:00 2001 From: Tyler Pennebaker Date: Wed, 23 Mar 2022 00:17:16 -0700 Subject: [PATCH 4/5] MNT: Add iocinfo function to reduce reused code --- scripts/ioctool | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/scripts/ioctool b/scripts/ioctool index f5d529c9..682d71da 100755 --- a/scripts/ioctool +++ b/scripts/ioctool @@ -9,17 +9,20 @@ function iocfpv { fi } -function iocdir { - ioc=$1 - iocpath="" - iocpath=$(grep_ioc "$ioc" all | grep "id:'$ioc'" | sed -n "s/^.*dir: '\(\S*\)'.*$/\1/p"); - if [[ -z $iocpath ]]; then - echo "Did not find ${ioc} running anywhere. Exiting..." >&2 +function iocinfo { + INFO="" + INFO=$(grep_ioc "$1" all | grep "id:'$NAME'") + if [ -z "$INFO" ]; then + echo "$1 could not be found. Exiting..." >&2 exit 1 fi - +} + +function iocdir { + iocinfo "$1" + iocpath=$(echo $INFO | sed -n "s/^.*dir: '\(\S*\)'.*$/\1/p"); if [[ ! $iocpath =~ ^/.* ]]; then - iocpath=/reg/g/pcds/epics/"${iocpath}" + iocpath=/reg/g/pcds/epics/"${iocpath}" fi } @@ -121,11 +124,7 @@ elif [ "$CMD" == "data" ]; then ################################################################# elif [ "$CMD" == "telnet" ]; then - INFO=$(grep_ioc "$NAME" all | grep "id:'$NAME'") - if [ -z "$INFO" ]; then - echo "$NAME could not be found. Exiting..." >&2 - exit 1 - fi + iocinfo "$NAME" HOST=$(echo "$INFO" | sed -n "s/^.*host: '\(\S*\)'.*$/\1/p") PORT=$(echo "$INFO" | sed -n "s/^.*port: \(\S*\),.*$/\1/p") #if [[ 39000 >= "$PORT" >=39999 ]]; @@ -135,10 +134,6 @@ elif [ "$CMD" == "telnet" ]; then elif [ "$CMD" == "host" ]; then - INFO=$(grep_ioc "$NAME" all | grep "id:'$NAME'") - if [ -z "$INFO" ]; then - echo "$NAME could not be found. Exiting..." >&2 - exit 1 - fi + iocinfo "$NAME" echo "$INFO" | sed -n "s/^.*host: '\(\S*\)'.*$/\1/p" fi From 1bb9e6f837d2ab23026778048155ab52cb8582f0 Mon Sep 17 00:00:00 2001 From: Tyler Pennebaker Date: Wed, 23 Mar 2022 00:20:43 -0700 Subject: [PATCH 5/5] ENH: Cleanup and add warning for unsupported option --- scripts/ioctool | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/ioctool b/scripts/ioctool index 682d71da..c6de2c34 100755 --- a/scripts/ioctool +++ b/scripts/ioctool @@ -24,7 +24,6 @@ function iocdir { if [[ ! $iocpath =~ ^/.* ]]; then iocpath=/reg/g/pcds/epics/"${iocpath}" fi - } function ioccfg { @@ -37,7 +36,6 @@ function ioccfg { exit 1 fi fi - } usage(){ @@ -132,8 +130,15 @@ elif [ "$CMD" == "telnet" ]; then echo "$HOST":"$PORT" telnet "$HOST" "$PORT" +################################################################# elif [ "$CMD" == "host" ]; then iocinfo "$NAME" echo "$INFO" | sed -n "s/^.*host: '\(\S*\)'.*$/\1/p" + +################################################################# + +else + echo "Command not supported: $CMD" >&2 + exit 1 fi