From 6ce273658b5887b73d8f96a393ae607c99359f2e Mon Sep 17 00:00:00 2001 From: Kaushik Malapati Date: Mon, 6 May 2024 13:35:33 -0700 Subject: [PATCH 1/3] MNT: Shellchecking bash scripts --- .shellcheckrc | 2 +- LICENSE.md | 62 +++++++------- README.md | 6 +- rc/vimrc | 1 - scripts/ami_offline_psana | 22 ++--- scripts/archive-resume | 4 +- scripts/archive-status | 4 +- scripts/camViewer | 68 +++++++-------- scripts/checkcnf | 1 + scripts/configdb_readxtc | 24 +++--- scripts/daq_control | 4 +- scripts/daq_waitwin | 16 ++-- scripts/dev_conda | 3 +- scripts/eloggrabber | 36 ++++---- scripts/get_curr_exp | 28 +++--- scripts/get_hutch_name | 12 +-- scripts/get_lastRun | 52 ++++++------ scripts/grep_ioc | 6 +- scripts/grep_pv | 12 +-- scripts/imgr | 6 +- scripts/iocmanager | 4 +- scripts/ioctool | 63 +++++++------- scripts/ipmConfigEpics | 130 ++++++++++++++-------------- scripts/kinit_helper | 2 +- scripts/makepeds | 80 ++++++++--------- scripts/makepeds_psana | 156 +++++++++++++++++----------------- scripts/motor-expert-screen | 49 +++++------ scripts/motor-typhos | 8 +- scripts/motorInfo | 89 ++++++++++--------- scripts/new_bare_repo | 2 +- scripts/pcds_conda | 1 - scripts/pkg_release | 10 +-- scripts/pmgr | 4 +- scripts/pydev_register | 2 +- scripts/restartdaq | 36 ++++---- scripts/serverStat | 37 ++++---- scripts/set_gem_timing | 4 +- scripts/startami | 48 +++++------ scripts/stopami | 36 ++++---- scripts/stopdaq | 5 +- scripts/takepeds | 14 +-- scripts/verify-hutch | 4 +- scripts/wheredaq | 2 +- scripts/wherepsana | 43 +++++----- scripts/xpp_update_happi_line | 2 +- 45 files changed, 594 insertions(+), 606 deletions(-) diff --git a/.shellcheckrc b/.shellcheckrc index 08c7738e..4db12541 100644 --- a/.shellcheckrc +++ b/.shellcheckrc @@ -1 +1 @@ -disable=SC1091 # allow sourcing files that can't immediately be found (pcds_conda) +disable=SC1091,SC2018,SC2019 # allow sourcing files that can't immediately be found (pcds_conda), disable warnings about supporting accents and foreign languages diff --git a/LICENSE.md b/LICENSE.md index 010b5a49..336b168d 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,39 +1,39 @@ -Copyright (c) 2018, The Board of Trustees of the Leland Stanford Junior -University, through SLAC National Accelerator Laboratory (subject to receipt -of any required approvals from the U.S. Dept. of Energy). All rights reserved. -Redistribution and use in source and binary forms, with or without +Copyright (c) 2018, The Board of Trustees of the Leland Stanford Junior +University, through SLAC National Accelerator Laboratory (subject to receipt +of any required approvals from the U.S. Dept. of Energy). All rights reserved. +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -(1) Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -(2) Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +(1) Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. -(3) Neither the name of the Leland Stanford Junior University, SLAC National - Accelerator Laboratory, U.S. Dept. of Energy nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. +(2) Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, THE UNITED STATES GOVERNMENT, -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +(3) Neither the name of the Leland Stanford Junior University, SLAC National + Accelerator Laboratory, U.S. Dept. of Energy nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, THE UNITED STATES GOVERNMENT, +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -You are under no obligation whatsoever to provide any bug fixes, patches, or -upgrades to the features, functionality or performance of the source code -("Enhancements") to anyone; however, if you choose to make your Enhancements -available either publicly, or directly to SLAC National Accelerator Laboratory, -without imposing a separate written license agreement for such Enhancements, -then you hereby grant the following license: a non-exclusive, royalty-free +You are under no obligation whatsoever to provide any bug fixes, patches, or +upgrades to the features, functionality or performance of the source code +("Enhancements") to anyone; however, if you choose to make your Enhancements +available either publicly, or directly to SLAC National Accelerator Laboratory, +without imposing a separate written license agreement for such Enhancements, +then you hereby grant the following license: a non-exclusive, royalty-free perpetual license to install, use, modify, prepare derivative works, incorporate -into other computer software, distribute, and sublicense such Enhancements or +into other computer software, distribute, and sublicense such Enhancements or derivative works thereof, in binary and source code form. diff --git a/README.md b/README.md index a6ae291f..c0ad9330 100644 --- a/README.md +++ b/README.md @@ -308,7 +308,7 @@ usage: ioctool <ioc>|<pv> [option]
telnet : starts a telnet session with the ioc
pvs : opens the IOC.pvlist file in less
- + ipmConfigEpics @@ -640,9 +640,9 @@ Optional arguments:
set_gem_timing - + Usage: set_gem_timing [SC or NC] - \ No newline at end of file + diff --git a/rc/vimrc b/rc/vimrc index 0838aaf0..c5ba6ec3 100644 --- a/rc/vimrc +++ b/rc/vimrc @@ -24,4 +24,3 @@ au FileType python \ autoindent \ fileformat=unix \ encoding=utf-8 - diff --git a/scripts/ami_offline_psana b/scripts/ami_offline_psana index 389f0e62..bc170e43 100755 --- a/scripts/ami_offline_psana +++ b/scripts/ami_offline_psana @@ -7,7 +7,7 @@ usage: $0 options We will run ami_offline OPTIONS: --e +-e -R rebinning (binned to 640x640) -n no plugins EOF @@ -30,7 +30,7 @@ do R) REBIN=1 ;; - n) + n) NOPLUG=1 ;; ?) @@ -44,14 +44,14 @@ if [ -z "$EXP" ]; then echo getting the experiment "$EXP" HUTCH=$(get_hutch_name) if [ "$HUTCH" == 'unknown_hutch' ]; then - read -p 'please enter an experiment name: ' EXP + read -rp 'please enter an experiment name: ' EXP else EXP=$(get_curr_exp) fi fi HUTCH=${EXP:0:3} -if [ -z $REBIN ]; then +if [[ -z $REBIN ]]; then ARGSTR=$ARGSTR' -R' fi @@ -69,7 +69,7 @@ fi ami_base_path=$(grep ami_base_path /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNF" | grep -v '#' | grep -v 'ami_base_path+' | tail -n 1 | awk 'BEGIN { FS = "=" }; { print $2}' | sed s/\'//g) ami_path=$ami_base_path$(grep ami_path /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNF" | grep -v 'ami_path+' | grep -v '#' | awk 'BEGIN { FS = "= " }; { print $2}' | sed s/ami_base_path+//g | sed s/\'//g) -if [ ! -f $ami_path/offline_ami ]; then +if [[ ! -f $ami_path/offline_ami ]]; then echo "could not find offline_ami executable in ""$ami_path" exit fi @@ -79,7 +79,7 @@ pp=$(grep plugin_path /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNF" | grep ami_ba plugin_path=$ami_base_path$pp plugin_str=$plugin_path'/libtimetooldbd.so' -if [ -z $NOPLUG ]; then +if [[ -z $NOPLUG ]]; then ARGSTR=$ARGSTR' -L '$plugin_str fi #ARGSTR=$ARGSTR -X /reg/neh/operator/$HUTCH\opr/experiments @@ -91,19 +91,19 @@ if [ "${HOSTNAME:0:5}" == 'psana' ]; then if [ "$HAVE_RUNS" == 0 ]; then echo 'did not find any xtc files in /reg/d/psdm/'"$HUTCH"'/'"$EXP"', will exit' exit - fi + fi elif [ "${HOSTNAME:0:3}" == 'drp' ]; then XTCDIR=/cds/data/drpsrcf/$HUTCH/$EXP/xtc/ HAVE_RUNS=$(find "$XTCDIR"/*r* | wc -l) if [ "$HAVE_RUNS" == 0 ]; then echo 'did not find any xtc files in /cds/data/drpsrcf/'"$HUTCH"'/'"$EXP"', will exit' exit - fi + fi elif [ "${HOSTNAME:8:3}" == 'rec' ]; then XTCDIR=/u2/REC/daq/xtc/ elif [ "${HOSTNAME:8:3}" == 'dss' ]; then EXPID=$(get_info --setExp "$EXP" --experimentNumber) - XTCDIR=/u2/pcds/pds/"$HUTCH"/e"$EXPID"/ + XTCDIR=/u2/pcds/pds/"$HUTCH"/e"$EXPID"/ else echo 'Please ssh to a psana, recorder or dss node to see data' exit @@ -124,6 +124,6 @@ LD_LIBRARY_PATH=/reg/g/pcds/dist/pds/"$HUTCH"/current/build/pds/lib/x86_64-linux #ARGSTR='-p '$XTCDIR $ARGSTR echo '----------------------------------------------' -echo "$ami_path"/offline_ami $ARGSTR -p $XTCDIR +echo "$ami_path"/offline_ami "$ARGSTR" -p "$XTCDIR" echo '----------------------------------------------' -$ami_path/offline_ami $ARGSTR -p $XTCDIR +"$ami_path"/offline_ami "$ARGSTR" -p "$XTCDIR" diff --git a/scripts/archive-resume b/scripts/archive-resume index 9fd8ba8e..05107287 100755 --- a/scripts/archive-resume +++ b/scripts/archive-resume @@ -12,7 +12,7 @@ if [[ -z $1 ]]; then usage exit 1 fi - + if [[ ($1 == "--help") || ($1 == "-h") ]]; then usage exit 0 @@ -20,5 +20,5 @@ fi result=$(curl -s "http://pscaa01.slac.stanford.edu:17665/mgmt/bpl/resumeArchivingPV?pv=$1") echo -echo $result | cut -d'{' -f2 | cut -d '}' -f1 | tr ',' '\n' +echo "$result" | cut -d'{' -f2 | cut -d '}' -f1 | tr ',' '\n' echo diff --git a/scripts/archive-status b/scripts/archive-status index 1ee864bf..0b525dfc 100755 --- a/scripts/archive-status +++ b/scripts/archive-status @@ -12,7 +12,7 @@ if [[ -z $1 ]]; then usage exit 1 fi - + if [[ ($1 == "--help") || ($1 == "-h") ]]; then usage exit 0 @@ -20,5 +20,5 @@ fi result=$(curl -s "http://pscaa01.slac.stanford.edu:17665/mgmt/bpl/getPVStatus?pv=$1") echo -echo $result | cut -d'{' -f2 | cut -d'}' -f1 | tr ',' '\n' +echo "$result" | cut -d'{' -f2 | cut -d'}' -f1 | tr ',' '\n' echo diff --git a/scripts/camViewer b/scripts/camViewer index 180d3a7a..65549e80 100755 --- a/scripts/camViewer +++ b/scripts/camViewer @@ -23,7 +23,7 @@ VIEWERCFG=/reg/g/pcds/pyps/config/$hutch/camviewer.cfg # Match "-" or "_" or " ". NAME=$(echo "$1" | sed -e 's/-/ /g' -e 's/_/ /g' -e 's/ /[-_ ]/g') # -# The story here: +# The story here: # See how many matches we have in the hutch. # If 0, try looking in all of the hutches. # If 1, then we're done. @@ -34,11 +34,12 @@ NAME=$(echo "$1" | sed -e 's/-/ /g' -e 's/_/ /g' -e 's/ /[-_ ]/g') # # Make a temp file with just the PVs and camera names that match. tmp=/tmp/cv.$$ -cat "$VIEWERCFG" | grep -i "$NAME" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp +grep -i "$NAME" "$VIEWERCFG" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp c=$(wc -l <$tmp) if [ "$c" -eq 0 ]; then - VIEWERCFG=/reg/g/pcds/pyps/config/*/camviewer.cfg - cat $VIEWERCFG | grep -i "$NAME" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp + VIEWERCFG="/reg/g/pcds/pyps/config/*/camviewer.cfg" + # shellcheck disable=SC2086 + grep -i "$NAME" $VIEWERCFG | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp c=$(wc -l <$tmp) if [ "$c" -eq 0 ]; then echo "No match for $1" @@ -52,14 +53,14 @@ if [ "$c" -eq 1 ]; then return fi # OK, ambiguous. Look for a complete match on the second word. -if [ "$(grep -E -i " $NAME\$" < $tmp | wc -l)" -eq 1 ]; then +if [ "$(grep -E -i -c " $NAME\$" < $tmp)" -eq 1 ]; then CAMPVFULL=$(grep -E -i " $NAME\$" < $tmp | awk '{print $1;}') rm -f $tmp return fi # What about just a match at the end? (That is, if we are searching # for "yag1", prefer "mec_yag1" to "mec_yag11".) -if [ "$(grep -E -i "$NAME\$" < $tmp | wc -l)" -eq 1 ]; then +if [ "$(grep -E -i -c "$NAME\$" < $tmp)" -eq 1 ]; then CAMPVFULL=$(grep -E -i "$NAME\$" < $tmp | awk '{print $1;}') rm -f $tmp return @@ -81,7 +82,7 @@ VIEWERCFG=/reg/g/pcds/pyps/config/$hutch/camviewer.cfg printf -v GIGENUM "%02d" "$2" GIGEBASE=$HUTCH:GIGE:$GIGENUM -echo "$(grep "$GIGEBASE" "$VIEWERCFG" | grep -v '#' | awk -F, '{print $4}')" +grep "$GIGEBASE" "$VIEWERCFG" | grep -v '#' | awk -F, '{print $4}' } isNum(){ @@ -103,27 +104,20 @@ fi HUTCH=$(echo "$1" | tr a-z A-Z) hutch=$(echo "$1" | tr A-Z a-z) -ALLVIEWERCFG=/reg/g/pcds/pyps/config/*/camviewer.cfg -echo cat $ALLVIEWERCFG | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' +ALLVIEWERCFG="/reg/g/pcds/pyps/config/*/camviewer.cfg" +echo grep -v '#' "$ALLVIEWERCFG" | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' VIEWERCFGLFE=/reg/g/pcds/pyps/config/lfe/camviewer.cfg -VIEWERCFG=/reg/g/pcds/pyps/config/$hutch/camviewer.cfg VIEWERCFGXRT=/reg/g/pcds/pyps/config/xrt/camviewer.cfg - +VIEWERCFG=/reg/g/pcds/pyps/config/$hutch/camviewer.cfg if [ "$hutch" != 'tmo' ] && [ "$hutch" != 'rix' ]; then - for gige_cam in $(grep -v '#' $VIEWERCFGLFE | awk -F, '{print $4 "\n"} '); do - echo "$gige_cam" - done - - for gige_cam in $(grep -v '#' $VIEWERCFGXRT | awk -F, '{print $4 "\n" }'); do - echo "$gige_cam" - done + grep -v '#' $VIEWERCFGLFE | awk -F, '{if ($4) print $4}' | sed 's/ //g' + grep -v '#' $VIEWERCFGXRT | awk -F, '{if ($4) print $4}' | sed 's/ //g' fi -for gige_cam in $(grep -v '#' "$VIEWERCFG" | awk -F, '{print $4 "\n" }'); do - echo "$gige_cam" -done - +if [ "$hutch" != 'lfe' ]; then +grep -v '#' "$VIEWERCFG" | awk -F, '{if ($4) print $4}' | sed 's/ //g' +fi } iocfpv() { @@ -138,7 +132,7 @@ iocinfo() { iochutch=$(echo "$INFO" | cut -d'/' -f7) fi done -} +} usage() { @@ -185,9 +179,10 @@ ACQUIRE=0 STOP=0 NUDGE=0 -OPTIONS=$(getopt -o lmredasnc:w:u:H: --long list,main,reboot,enable,disable,acquire,stop,nudge,cam:,wait:,rate:,hutch: -n \'$0\' -- "$@") - -if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi +if ! OPTIONS=$(getopt -o lmredasnc:w:u:H: --long list,main,reboot,enable,disable,acquire,stop,nudge,cam:,wait:,rate:,hutch: -n \'"$0"\' -- "$@"); then + echo "Terminating..." >&2 + exit 1 +fi @@ -195,10 +190,10 @@ eval set -- "$OPTIONS" -while [ : ] +while [[ $# -gt 0 ]] do case "$1" in - -l|--list) + -l|--list) LIST=1 shift ;; @@ -246,9 +241,9 @@ do usage break ;; - --) - shift - break + --) + shift + break ;; *) echo "Internal Error" @@ -259,7 +254,7 @@ do done if [ $# -ge 1 ]; then - echo "Positional arguments unsupported: $@" >&2 + echo "Positional arguments unsupported: $*" >&2 usage exit 1 fi @@ -320,17 +315,18 @@ name_to_pv "$CAMNAME" "$hutch" if [ $MAINSCREEN -gt 0 ]; then tmp=/tmp/cv.$$ list_cams "$hutch" >$tmp - c=$(wc <$tmp | grep "$CAMNAME" $tmp | awk '{print $1}') + + c=$(wc $tmp | grep "$CAMNAME" $tmp | awk '{print $1}') # not sure what is happening here if [ "$c" == '' ]; then echo "Camera name not found in hutch. To see which cameras you can access from your current machine use the '-l/--list' option." sleep 3 elif [ "$c" == "$CAMNAME" ] && [ "$hutch" != "$(get_info --gethutch)" ] ; then - echo "To use camera controls, you must be on the same hutch machine as your camera." + echo "To use camera controls, you must be on the same hutch machine as your camera." echo "Opening read-only main screen..." sleep 3 - + rm -f $tmp - fi + fi echo 'try to get the main screen for: ' "$CAMNAME" echo 'start the main screen for camera base PV: ' "$CAMPVFULL" cmdName=$(caget -St "$CAMPVFULL":LAUNCH_EDM) diff --git a/scripts/checkcnf b/scripts/checkcnf index 81e22af1..b9d53e7d 100755 --- a/scripts/checkcnf +++ b/scripts/checkcnf @@ -18,6 +18,7 @@ HUTCH=$(get_info --gethutch) LCLS2_HUTCHES="rix, tmo, ued" if echo "$LCLS2_HUTCHES" | grep -iw "$HUTCH" > /dev/null; then + # shellcheck source=/reg/g/pcds/dist/pds/rix/scripts/setup_env.sh source /reg/g/pcds/dist/pds/"$HUTCH"/scripts/setup_env.sh PROCMGR='procmgr' else diff --git a/scripts/configdb_readxtc b/scripts/configdb_readxtc index 453a05f6..80a9d803 100755 --- a/scripts/configdb_readxtc +++ b/scripts/configdb_readxtc @@ -8,7 +8,7 @@ We will run configdb_readxtc OPTIONS: -u user (needs to be able to log into the psananeh/feh) --e expnumber +-e expnumber EOF } @@ -17,7 +17,7 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then exit 0 fi -USER=`whoami` +USER=$(whoami) ARGSTR='' while getopts "u:e:" OPTION @@ -37,10 +37,10 @@ do done if [[ $USER =~ "opr" ]]; then - printf "Please enter user name (cannot run as xppopr): \n"; read USER + printf "Please enter user name (cannot run as xppopr): \n"; read -r USER fi -: ${EXP:=`get_curr_exp`} +: "${EXP:=$(get_curr_exp)}" HUTCH=${EXP:0:3} # check if experiment is passed, then use that @@ -54,15 +54,13 @@ HUTCH=${EXP:0:3} # opt_dir="/reg/g/pcds/dist/pds/$HUTCH/current/build/pdsapp/bin/x86_64-rhel7-opt" -eval find $opt_dir/configdb_readxtc +eval find "$opt_dir"/configdb_readxtc ret_code=$? if [ $ret_code == 0 ]; then EXE='/reg/g/pcds/dist/pds/'$HUTCH'/current/build/pdsapp/bin/x86_64-rhel7-opt/configdb_readxtc' else dir="/reg/g/pcds/dist/pds/xpp/current/build/pdsapp/bin/x86_64-rhel7" - eval find $dir/configdb_readxtc - ret_code=$? - if [ $ret_code2 == 0 ]; then + if eval find $dir/configdb_readxtc; then EXE='/reg/g/pcds/dist/pds/'$HUTCH'/current/build/pdsapp/bin/x86_64-rhel7/configdb_readxtc' else echo 'could not find configdb_readxtc executable' @@ -74,12 +72,10 @@ fi # check hostname,only ssh if on control machine. # if [[ $HOSTNAME =~ "psana" ]]; then - $EXE /reg/d/psdm/$HUTCH/$EXP/xtc + $EXE /reg/d/psdm/"$HUTCH"/"$EXP"/xtc elif [[ $HOSTNAME =~ "psusr" ]]; then - ssh -Y $USER@psana "$EXE /reg/d/psdm/$HUTCH/$EXP/xtc" + ssh -Y "$USER"@psana "$EXE /reg/d/psdm/$HUTCH/$EXP/xtc" else - echo $EXE /reg/d/psdm/$HUTCH/$EXP/xtc - ssh -Y $USER@psdev ssh -Y psana "$EXE /reg/d/psdm/$HUTCH/$EXP/xtc" + echo "$EXE /reg/d/psdm/$HUTCH/$EXP/xtc" + ssh -Y "$USER"@psdev ssh -Y psana "$EXE /reg/d/psdm/$HUTCH/$EXP/xtc" fi - - diff --git a/scripts/daq_control b/scripts/daq_control index dca68c5e..a788c9fb 100755 --- a/scripts/daq_control +++ b/scripts/daq_control @@ -1,6 +1,6 @@ #!/bin/bash cat << EOF -This tool is deprecated. Please let your ECS staff -know what you were trying to do in case you are not +This tool is deprecated. Please let your ECS staff +know what you were trying to do in case you are not aware of a supported alternative EOF diff --git a/scripts/daq_waitwin b/scripts/daq_waitwin index bba8fa31..1a005cd7 100755 --- a/scripts/daq_waitwin +++ b/scripts/daq_waitwin @@ -17,14 +17,14 @@ source /reg/g/pcds/setup/pathmunge.sh ldpathmunge /usr/local/lib -if [[ $# > 0 ]]; then +if [[ $# -gt 0 ]]; then SEARCHOPT='--onlyvisible --maxdepth 2 --limit 1 --all --desktop '$1' --sync ' -else +else SEARCHOPT='--onlyvisible --maxdepth 2 --limit 1 --all --sync ' fi -proc=`xdotool search $SEARCHOPT --name 'ProcStat'` -ami=`xdotool search $SEARCHOPT --name 'DAQ Online Monitoring'` -env=`xdotool search $SEARCHOPT --name 'Env'` -crwin=`xdotool search $SEARCHOPT --name 'DAQ Control'` -echo $proc $ami $env $crwin -exit \ No newline at end of file +proc=$(xdotool search "$SEARCHOPT" --name 'ProcStat') +ami=$(xdotool search "$SEARCHOPT" --name 'DAQ Online Monitoring') +env=$(xdotool search "$SEARCHOPT" --name 'Env') +crwin=$(xdotool search "$SEARCHOPT" --name 'DAQ Control') +echo "$proc $ami $env $crwin" +exit diff --git a/scripts/dev_conda b/scripts/dev_conda index f23219d7..35762b2d 100755 --- a/scripts/dev_conda +++ b/scripts/dev_conda @@ -2,7 +2,7 @@ usage() { cat << EOF -usage: source $0 +usage: source $0 Source this to activate the latest version a pcds conda environment. EOF @@ -64,4 +64,3 @@ if [ -n "${SSH_CONNECTION}" ]; then fi fi fi - diff --git a/scripts/eloggrabber b/scripts/eloggrabber index 90be0619..c264a30a 100755 --- a/scripts/eloggrabber +++ b/scripts/eloggrabber @@ -26,9 +26,9 @@ grab() exit fi LogBookGrabber_qt \ - -i $HUTCH \ - -e $1 \ - -u $USERNAME \ + -i "$HUTCH" \ + -e "$1" \ + -u "$USERNAME" \ -p pcds \ -w https://pswww.slac.stanford.edu/ws-auth/lgbk exit @@ -38,21 +38,21 @@ grab() grab_script() { LogBookGrabber_qt \ - -i $HUTCH \ - -e $EXPNAME \ - -u $USERNAME \ + -i "$HUTCH" \ + -e "$EXPNAME" \ + -u "$USERNAME" \ -p pcds \ -w https://pswww.slac.stanford.edu/ws-auth/lgbk \ - -c $SCRIPT + -c "$SCRIPT" exit 1 } grab_user() { LogBookGrabber_qt \ - -i $HUTCH \ - -e $1 \ - -u $USERNAME \ + -i "$HUTCH" \ + -e "$1" \ + -u "$USERNAME" \ -w https://pswww.slac.stanford.edu/ws-kerb/lgbk exit } @@ -67,7 +67,7 @@ grab_instrument() LogBookGrabber_qt \ -i OPS \ -e "$EXPNAME" \ - -u $USERNAME \ + -u "$USERNAME" \ -p pcds \ -w https://pswww.slac.stanford.edu/ws-auth/lgbk exit @@ -79,7 +79,7 @@ grab_controls() LogBookGrabber_qt \ -i OPS \ -e "$EXPNAME" \ - -u $USERNAME \ + -u "$USERNAME" \ -p pcds \ -w https://pswww.slac.stanford.edu/ws-auth/lgbk exit @@ -92,9 +92,9 @@ fi ##who am I doing this? Why don't just use the actual username? #USERNAME=`get_info --gethutch`opr -USERNAME=`whoami` -EXPNAME=`get_curr_exp` -HUTCH=`get_info --gethutch` +USERNAME=$(whoami) +EXPNAME=$(get_curr_exp) +HUTCH=$(get_info --gethutch) while getopts "e:u:s:xct" OPTION do @@ -105,7 +105,7 @@ do ;; u) USERNAME=$OPTARG - grab_user $EXPNAME + grab_user "$EXPNAME" ;; s) SCRIPT=$OPTARG @@ -125,7 +125,7 @@ do done if [[ $USERNAME == *'opr'* ]]; then - grab $EXPNAME + grab "$EXPNAME" else - grab_user $EXPNAME + grab_user "$EXPNAME" fi diff --git a/scripts/get_curr_exp b/scripts/get_curr_exp index da2ceeb9..c3595163 100755 --- a/scripts/get_curr_exp +++ b/scripts/get_curr_exp @@ -19,10 +19,10 @@ fi while getopts "H:i:le" OPTION do case $OPTION in - i) + i) INSTRUMENT=$OPTARG ;; - H) + H) INSTRUMENT=$OPTARG ;; ?) @@ -32,23 +32,23 @@ do esac done -DIRTMP=`dirname "${BASH_SOURCE[0]}"` -DIR="$( cd $DIRTMP && pwd -P )" +DIRTMP=$(dirname "${BASH_SOURCE[0]}") +DIR=$(cd "$DIRTMP" && pwd -P) PATH=$PATH:$DIR -if [ $INSTRUMENT != 'xxx' ]; then - CURR_EXP=`get_info --hutch ${INSTRUMENT^^} --exp` +if [[ $INSTRUMENT != 'xxx' ]]; then + CURR_EXP=$(get_info --hutch "${INSTRUMENT^^}" --exp) else - CURR_EXP=`get_info --exp` - if [ $CURR_EXP == 'unknown_hutch' ]; then - echo 'Cannot autodetermine hutch, for which hutch would you like to get this information? ' - read -t 5 hutch - if [ $hutch == '' ]; then + CURR_EXP=$(get_info --exp) + if [[ $CURR_EXP == 'unknown_hutch' ]]; then + echo 'Cannot autodetermine hutch, for which hutch would you like to get this information?' + read -rt 5 hutch + if [[ $hutch == '' ]]; then echo 'no response, will quit' exit 1 fi - CURR_EXP=`get_info --hutch ${hutch^^} --exp` + CURR_EXP=$(get_info --hutch "${hutch^^}" --exp) fi fi - -echo $CURR_EXP + +echo "$CURR_EXP" diff --git a/scripts/get_hutch_name b/scripts/get_hutch_name index 84a6fa9e..76d46816 100755 --- a/scripts/get_hutch_name +++ b/scripts/get_hutch_name @@ -2,7 +2,7 @@ usage() { cat << EOF -usage: $0 +usage: $0 Returns the hutch name based on the host it is run on EOF @@ -13,9 +13,9 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then exit 0 fi -DIRTMP=`dirname "${BASH_SOURCE[0]}"` -DIR="$( cd $DIRTMP && pwd -P )" -PATH=$PATH:$DIR +DIRTMP=$(dirname "${BASH_SOURCE[0]}") +DIR=$(cd "$DIRTMP" && pwd -P) +PATH="$PATH:$DIR" -hutch=`get_info --gethutch` -echo $hutch +hutch=$(get_info --gethutch) +echo "$hutch" diff --git a/scripts/get_lastRun b/scripts/get_lastRun index a7442f75..072870af 100755 --- a/scripts/get_lastRun +++ b/scripts/get_lastRun @@ -19,23 +19,23 @@ AskLive=0 Ended=0 INSTRUMENT='xxx' -DIRTMP=`dirname "${BASH_SOURCE[0]}"` -DIR="$( cd $DIRTMP && pwd -P )" +DIRTMP=$(dirname "${BASH_SOURCE[0]}") +DIR=$(cd "$DIRTMP" && pwd -P) PATH=$PATH:$DIR while getopts "H:i:le" OPTION do case $OPTION in - l) + l) AskLive=1 ;; - e) + e) Ended=1 ;; - i) + i) INSTRUMENT=$OPTARG ;; - H) + H) INSTRUMENT=$OPTARG ;; ?) @@ -46,40 +46,40 @@ do done if [ $AskLive -eq 1 ]; then - if [ $INSTRUMENT != 'xxx' ]; then - CURR_EXP=`get_info --hutch $INSTRUMENT --run --live` + if [[ $INSTRUMENT != 'xxx' ]]; then + CURR_EXP=$(get_info --hutch "$INSTRUMENT" --run --live) else - CURR_EXP=`get_info --run --live` + CURR_EXP=$(get_info --run --live) if [[ $CURR_EXP == *'xxx'* ]]; then echo 'For which hutch would you like to get this information? ' - read hutch - CURR_EXP=`get_info --hutch $hutch --run --live` + read -r hutch + CURR_EXP=$(get_info --hutch "$hutch" --run --live) fi fi elif [ $Ended -eq 1 ]; then - if [ $INSTRUMENT != 'xxx' ]; then - CURR_EXP=`get_info --hutch $INSTRUMENT --run --ended` + if [[ $INSTRUMENT != 'xxx' ]]; then + CURR_EXP=$(get_info --hutch "$INSTRUMENT" --run --ended) else - CURR_EXP=`get_info --run --ended` + CURR_EXP=$(get_info --run --ended) if [[ $CURR_EXP == *'xxx'* ]]; then echo 'For which hutch would you like to get this information? ' - read hutch - CURR_EXP=`get_info --hutch $hutch --run --ended` + read -r hutch + CURR_EXP=$(get_info --hutch "$hutch" --run --ended) fi fi else - if [ $INSTRUMENT != 'xxx' ]; then - CURR_EXP=`get_info --hutch $INSTRUMENT --run` + if [[ $INSTRUMENT != 'xxx' ]]; then + CURR_EXP=$(get_info --hutch "$INSTRUMENT" --run) else - CURR_EXP=`get_info --run` + CURR_EXP=$(get_info --run) fi - NUM_RET_WORD=`echo $CURR_EXP | wc | awk {'print $2'}` - if [ $NUM_RET_WORD == 1 ]; then - if [ $CURR_EXP == 'xxx' ]; then - echo 'For which hutch would you like to get this information? ' - read hutch - CURR_EXP=`get_info --hutch $hutch --run` + NUM_RET_WORD=$(echo "$CURR_EXP" | wc | awk '{print $2}') + if [[ $NUM_RET_WORD == 1 ]]; then + if [[ $CURR_EXP == 'xxx' ]]; then + echo 'For which hutch would you like to get this information?' + read -r hutch + CURR_EXP=$(get_info --hutch "$hutch" --run) fi fi fi -echo $CURR_EXP +echo "$CURR_EXP" diff --git a/scripts/grep_ioc b/scripts/grep_ioc index df78cb38..04d89e5d 100755 --- a/scripts/grep_ioc +++ b/scripts/grep_ioc @@ -23,8 +23,8 @@ fi if [[ -z $2 ]]; then HUTCH="all" else - for hutchname in "xpp" "xcs" "cxi" "mfx" "mec" "tmo" "rix" "xrt" "aux" "det" "fee" "hpl" "icl" "las" "lfe" "kfe" "tst" "thz" "all"; do - if [[ "${2}" == $hutchname ]]; then + for hutchname in "xpp" "xcs" "cxi" "mfx" "mec" "tmo" "rix" "xrt" "aux" "det" "fee" "hpl" "icl" "las" "lfe" "kfe" "tst" "thz" "all"; do + if [[ "${2}" == "$hutchname" ]]; then HUTCH=$hutchname fi done @@ -35,6 +35,6 @@ else if [[ $HUTCH == "all" ]]; then grep -i "${1}" /reg/g/pcds/pyps/config/*/iocmanager.cfg else - grep -i "${1}" /reg/g/pcds/pyps/config/${HUTCH}/iocmanager.cfg + grep -i "${1}" /reg/g/pcds/pyps/config/"$HUTCH"/iocmanager.cfg fi fi diff --git a/scripts/grep_pv b/scripts/grep_pv index af5d05d4..7ff1cf68 100755 --- a/scripts/grep_pv +++ b/scripts/grep_pv @@ -17,20 +17,20 @@ KEYWORD=$1 if [[ -n $KEYWORD ]]; then cd /reg/d/iocData/ - for i in ioc-*; do - cd /reg/d/iocData/$i + for i in ioc-*; do + cd /reg/d/iocData/"$i" if [ -e ./iocInfo/ ] ; then cd iocInfo if [ -e ./IOC.pvlist ] ; then - if grep -q $KEYWORD IOC.pvlist - then + if grep -q "$KEYWORD" IOC.pvlist + then pwd - grep $KEYWORD IOC.pvlist; + grep "$KEYWORD" IOC.pvlist; echo "" else : fi - fi + fi fi cd ../../ done diff --git a/scripts/imgr b/scripts/imgr index aaf6d0fd..596cd67c 100755 --- a/scripts/imgr +++ b/scripts/imgr @@ -18,7 +18,7 @@ imgr IOCNAME [--hutch HUTCH] --upgrade RELEASE_DIR imgr IOCNAME [--hutch HUTCH] --move HOST imgr IOCNAME [--hutch HUTCH] --move HOST:PORT imgr [--hutch HUTCH] --list [--host HOST] [--enabled_only|--disabled_only] - + EOF } if [ $# -lt 1 ]; then @@ -68,7 +68,7 @@ else export IOC_DATA=/cds/data/iocData export IOC_COMMON=/cds/data/iocCommon fi -PSPKG_OS=$(${PSPKG_ROOT}/etc/pspkg_os.sh) +PSPKG_OS=$("$PSPKG_ROOT"/etc/pspkg_os.sh) export PSPKG_OS if [ "$PSPKG_OS" == rhel5 ]; then echo "IocManager 2.0.0 and higher does not run on RHEL5!" >&2 @@ -76,6 +76,6 @@ if [ "$PSPKG_OS" == rhel5 ]; then fi export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb export PSPKG_RELEASE=controls-0.1.9 -source $PSPKG_ROOT/etc/set_env.sh +source "$PSPKG_ROOT"/etc/set_env.sh /reg/g/pcds/pyps/config/"${HUTCH,,}"/iocmanager/imgr.py "$@" --hutch "${HUTCH,,}" diff --git a/scripts/iocmanager b/scripts/iocmanager index fd8eaf82..3d241826 100755 --- a/scripts/iocmanager +++ b/scripts/iocmanager @@ -38,7 +38,7 @@ else export IOC_DATA=/reg/d/iocData export IOC_COMMON=/reg/d/iocCommon fi -PSPKG_OS=$(${PSPKG_ROOT}/etc/pspkg_os.sh) +PSPKG_OS=$("$PSPKG_ROOT"/etc/pspkg_os.sh) export PSPKG_OS if [ "$PSPKG_OS" == rhel5 ]; then echo "IocManager 2.0.0 and higher does not run on RHEL5!" @@ -46,7 +46,7 @@ if [ "$PSPKG_OS" == rhel5 ]; then fi export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb export PSPKG_RELEASE=controls-0.1.9 -source $PSPKG_ROOT/etc/set_env.sh +source "$PSPKG_ROOT"/etc/set_env.sh ulimit -c unlimited /reg/g/pcds/pyps/config/"${HUTCH,,}"/iocmanager/IocManager.py --hutch "${HUTCH,,}" > /dev/null & diff --git a/scripts/ioctool b/scripts/ioctool index 78f71e7d..ed915e4b 100755 --- a/scripts/ioctool +++ b/scripts/ioctool @@ -4,10 +4,10 @@ function iocfpv { ioc="" ioc=$(grep_pv "$1" | cut -d'/' -f5 -s) if [ -z "$ioc" ]; then - echo "Did not find an ioc associated with this PV." >&2 + echo "Did not find an ioc associated with this PV." >&2 exit 1 elif [[ $ioc = *[[:space:]]* ]]; then # multiple iocs found if space present - ioccount=$(echo $ioc | wc -w) + ioccount=$(echo "$ioc" | wc -w) echo "$1 is found in $ioccount places" echo "Which ioc do you care about here? (press enter to exit)" printf '%s\n' "$ioc" >&2 @@ -17,8 +17,8 @@ function iocfpv { exit 0 fi ioc=$chosenioc - fi - + fi + } function iocdir { @@ -29,9 +29,9 @@ function iocdir { echo "Did not find ${ioc} running anywhere. Exiting..." >&2 exit 1 fi - + if [[ ! $iocpath =~ ^/.* ]]; then - iocpath=/reg/g/pcds/epics/"${iocpath}" + iocpath=/reg/g/pcds/epics/"${iocpath}" fi } @@ -51,7 +51,7 @@ function ioccfg { function camname_to_pv { - #A function that will loop through camviewer.cfg files throughout all hutches to find the name then use that to search for its PV + #A function that will loop through camviewer.cfg files throughout all hutches to find the name then use that to search for its PV campv="" hutch="$1" if [ "$1" == "" ]; then @@ -62,13 +62,13 @@ function camname_to_pv { exit 1 fi fi - + VIEWERCFG=/reg/g/pcds/pyps/config/$hutch/camviewer.cfg CAMNAME=$(echo "$2" | sed -e 's/-/ /g' -e 's/_/ /g' -e 's/ /[-_ ]/g') - - - # The story here: + + + # The story here: # See how many matches we have in the hutch. # If 0, try looking in all of the hutches. # If 1, then we're done. @@ -79,17 +79,17 @@ function camname_to_pv { # # Make a temp file with just the PVs and camera names that match. tmp=/tmp/cv.$$ - cat $VIEWERCFG | grep -i "$CAMNAME" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp + grep -i "$CAMNAME" "$VIEWERCFG" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp c=$(wc -l <$tmp) - if [ "$c" -eq 0 ]; then - VIEWERCFG=/reg/g/pcds/pyps/config/*/camviewer.cfg - cat $VIEWERCFG | grep -i "$CAMNAME" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp - c=$(wc -l <$tmp) - if [ "$c" -eq 0 ]; then - echo "No match for $2" - rm -f $tmp - exit - fi + if [ "$c" -eq 0 ]; then + VIEWERCFG="/reg/g/pcds/pyps/config/*/camviewer.cfg" + grep -i "$CAMNAME" "$VIEWERCFG" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp + c=$(wc -l <$tmp) + if [ "$c" -eq 0 ]; then + echo "No match for $2" + rm -f $tmp + exit + fi fi if [ "$c" -eq 1 ]; then campv=$(awk '{print $1;}' <$tmp) @@ -97,14 +97,14 @@ function camname_to_pv { return fi # OK, ambiguous. Look for a complete match on the second word. - if [ "$(grep -E -i "$CAMNAME\$" < $tmp | wc -l)" -eq 1 ]; then + if [ "$(grep -E -i -c "$CAMNAME\$" < $tmp)" -eq 1 ]; then campv=$(grep -E -i "$CAMNAME\$" < $tmp | awk '{print $1;}') rm -f $tmp return fi # What about just a match at the end? (That is, if we are searching # for "yag1", prefer "mec_yag1" to "mec_yag11".) - if [ "$(grep -E -i "$CAMNAME\$" < $tmp | wc -l)" -eq 1 ]; then + if [ "$(grep -E -i -c "$CAMNAME\$" < $tmp)" -eq 1 ]; then campv=$(grep -E -i "$CAMNAME\$" < $tmp | awk '{print $1;}') rm -f $tmp return @@ -143,8 +143,7 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then exit 0 fi -OPTIONS=$(getopt -o H: --long hutch: -n \'$0\' -- "$@") -if [ $? != 0 ]; then +if OPTIONS=$(getopt -o H: --long hutch: -n \'"$0"\' -- "$@"); then echo "Terminating..." >&2 exit 1 fi @@ -194,22 +193,22 @@ if [[ $NAME == *':'* ]]; then #we are assuming that PVs have a colon in them #2) If so, then search for ioc using grep_ioc #3) If that returns nothing, try converting the camera name to a PV and search for that #4) If neither of those produce results return "Did not find name anywhere" -elif [[ $NAME == *'-'* || $NAME == *'_'* || ^[[:alnum:]]+$ ]]; then +elif [[ $NAME == *'-'* || $NAME == *'_'* || $NAME =~ ^[[:alnum:]]+$ ]]; then INFO=$(grep_ioc "$NAME" all | grep "id:'$NAME'") if [ -z "$INFO" ]; then #echo "Hutch = $hutch" camname_to_pv "$hutch" "$NAME" iocfpv "$campv" NAME="$ioc" - + elif [[ -z "$NAME" ]]; then echo "Did not find ${NAME} running anywhere. Exiting..." >&2 exit 1 - fi + fi elif [[ ! $NAME == *'-'* ]]; then #We are assuming that ioc names contain a dash in them echo "${NAME} does not match the format for PVs or IOC names. Exiting..." >&2 - exit 1 + exit 1 fi @@ -232,9 +231,9 @@ elif [ "$CMD" == "cddir" ]; then echo "Script is not being sourced. Start with 'source $0' before calling script with this option." >&2 exit 1 fi - cd "${iocpath}" + cd "${iocpath}" + - ################################################################# elif [ "$CMD" == "cfg" ]; then @@ -306,7 +305,7 @@ elif [ "$CMD" == "telnet" ]; then echo "$HOST":"$PORT" telnet "$HOST" "$PORT" -################################################################# +################################################################# elif [ "$CMD" == "pvs" ]; then pvlistfile=/cds/data/iocData/"${NAME}"/iocInfo/IOC.pvlist diff --git a/scripts/ipmConfigEpics b/scripts/ipmConfigEpics index 66eed76e..ad1fc5e0 100755 --- a/scripts/ipmConfigEpics +++ b/scripts/ipmConfigEpics @@ -16,18 +16,18 @@ lfeIpm='um6_ipm hfxdg2_ipm pim3m' ipmList() { printf 'Possible boxes:\n' -if [ $hutch == 'xcs' ]; then - for box in $hx2Ipm $um6Ipm $dg2Ipm $xcsIpm; do echo $box; done -elif [ $hutch == 'xpp' ]; then - for box in $hx2Ipm $xppIpm; do echo $box; done -elif [ $hutch == 'cxi' ]; then - for box in $hx2Ipm $um6Ipm $dg2Ipm $cxiIpm; do echo $box; done -elif [ $hutch == 'mfx' ]; then - for box in $hx2Ipm $um6Ipm $mfxIpm; do echo $box; done -elif [ $hutch == 'mec' ]; then - for box in $hx2Ipm $um6Ipm $mecIpm; do echo $box; done -elif [ $hutch == 'lfe' ]; then - for box in $lfeIpm; do echo $box; done +if [[ $hutch == 'xcs' ]]; then + for box in $hx2Ipm $um6Ipm $dg2Ipm $xcsIpm; do echo "$box"; done +elif [[ $hutch == 'xpp' ]]; then + for box in $hx2Ipm $xppIpm; do echo "$box"; done +elif [[ $hutch == 'cxi' ]]; then + for box in $hx2Ipm $um6Ipm $dg2Ipm $cxiIpm; do echo "$box"; done +elif [[ $hutch == 'mfx' ]]; then + for box in $hx2Ipm $um6Ipm $mfxIpm; do echo "$box"; done +elif [[ $hutch == 'mec' ]]; then + for box in $hx2Ipm $um6Ipm $mecIpm; do echo "$box"; done +elif [[ $hutch == 'lfe' ]]; then + for box in $lfeIpm; do echo "$box"; done else echo 'hutch cannot be determined, quit' exit @@ -42,189 +42,189 @@ if [ $# -lt 1 ]; then fi # Shared IPMs -if [ $1 == 'hx2_ipm' ]; then +if [[ $1 == 'hx2_ipm' ]]; then IOC="IOC:HX2:SB1:BMMON" BASE='HX2:SB1:BMMON' EVR='HX2:SB1:BMMON:EVR' WAVE8='hx2_ipm' -elif [ $1 == 'um6_ipm' ]; then #aka xcs ipm1 +elif [[ $1 == 'um6_ipm' ]]; then #aka xcs ipm1 BASE="XCS:DG1:IMB:01" IOC="XCS:R04:IOC:34" EVR="XCS:R04:EVR:34" -elif [ $1 == 'um6_dio' ]; then #aka xcs ipm1 +elif [[ $1 == 'um6_dio' ]]; then #aka xcs ipm1 BASE="XCS:DG1:IMB:02" IOC="XCS:R04:IOC:34" EVR="XCS:R04:EVR:34" -elif [ $1 == 'hfxdg2_ipm' ]; then #aka xcs ipm2 +elif [[ $1 == 'hfxdg2_ipm' ]]; then #aka xcs ipm2 IOC="IOC:HFX:DG2:BMMON" BASE='HFX:DG2:BMMON' EVR='HFX:DG2:BMMON:EVR' WAVE8='hfxipm' -elif [ $1 == 'pim3m' ]; then +elif [[ $1 == 'pim3m' ]]; then BASE="HFX:DG3:IMB:02" IOC="XCS:R38:IOC:43" EVR="XCS:R38:EVR:43" fi # Hutch-specific IPMs -if [ $hutch == 'xcs' ]; then - if [ $1 == 'decmono' ]; then +if [[ $hutch == 'xcs' ]]; then + if [[ $1 == 'decmono' ]]; then BASE="HFX:MON:IMB:03" IOC="XCS:R38:IOC:43" EVR="XCS:R38:EVR:43" - elif [ $1 == 'diomono' ]; then + elif [[ $1 == 'diomono' ]]; then BASE="HFX:MON:IMB:02" IOC="XCS:R38:IOC:43" EVR="XCS:R38:EVR:43" - elif [ $1 == 'ipmmono' ]; then + elif [[ $1 == 'ipmmono' ]]; then BASE="HFX:MON:IMB:01" IOC="XCS:R38:IOC:43" EVR="XCS:R38:EVR:43" - elif [ $1 == 'pim3' ]; then + elif [[ $1 == 'pim3' ]]; then BASE="XCS:DG3:IMB:04" IOC="XCS:R38:IOC:43" EVR="XCS:R38:EVR:43" - elif [ $1 == 'ipm3' ]; then + elif [[ $1 == 'ipm3' ]]; then BASE="XCS:DG3:IMB:03" IOC="XCS:R38:IOC:43" EVR="XCS:R38:EVR:43" - elif [ $1 == 'ipm4' ]; then + elif [[ $1 == 'ipm4' ]]; then IOC="IOC:XCS:SB1:BMMON" BASE='XCS:SB1:BMMON' EVR='XCS:SB1:BMMON:EVR' WAVE8='sb1bmmon' - elif [ $1 == 'pim4' ]; then + elif [[ $1 == 'pim4' ]]; then BASE="XCS:SB1:IMB:02" IOC="IOC:XCS:IPM" EVR="XCS:R44:EVR:01" - elif [ $1 == 'ipm5' ]; then + elif [[ $1 == 'ipm5' ]]; then IOC="IOC:XCS:SB2:BMMON" BASE='XCS:SB2:BMMON' EVR='XCS:SB2:BMMON:EVR' WAVE8='sb2bmmon' - elif [ $1 == 'pim5' ]; then + elif [[ $1 == 'pim5' ]]; then BASE="XCS:SB2:IMB:02" IOC="IOC:XCS:IPM" EVR="XCS:R44:EVR:01" - elif [ $1 == 'ipmgonLD' ]; then + elif [[ $1 == 'ipmgonLD' ]]; then BASE="XCS:USR:IMB:01" IOC="IOC:XCS:USR:IPM" EVR="XCS:R42:EVR:01" - elif [ $1 == 'ipmlamLD' ]; then + elif [[ $1 == 'ipmlamLD' ]]; then BASE="XCS:LAM:IMB:02" IOC="IOC:XCS:IPM" EVR="XCS:R44:EVR:01" - elif [ $1 == 'snddio' ]; then + elif [[ $1 == 'snddio' ]]; then IOC="IOC:XCS:SND:DIO" BASE='XCS:SND:DIO' EVR='XCS:SND:DIO:EVR' WAVE8='snddio' fi -elif [ $hutch == 'cxi' ]; then - if [ $1 == 'dg2ipm' ]; then +elif [[ $hutch == 'cxi' ]]; then + if [[ $1 == 'dg2ipm' ]]; then IOC="IOC:CXI:DG2:BMMON" BASE='CXI:DG2:BMMON' EVR='CXI:DG2:BMMON:EVR' WAVE8='dg2ipm' - elif [ $1 == 'dg3ipm' ]; then + elif [[ $1 == 'dg3ipm' ]]; then IOC="IOC:CXI:DG3:BMMON" BASE='CXI:DG3:BMMON' EVR='CXI:DG3:BMMON:EVR' WAVE8='dg3ipm' - elif [ $1 == 'usrdio' ]; then + elif [[ $1 == 'usrdio' ]]; then IOC="IOC:CXI:USR:DIO" BASE='CXI:USR:DIO' EVR='CXI:USR:DIO:EVR' WAVE8='usrdio' fi -elif [ $hutch == 'mfx' ]; then - if [ $1 == 'dg1ipm' ]; then +elif [[ $hutch == 'mfx' ]]; then + if [[ $1 == 'dg1ipm' ]]; then IOC="IOC:MFX:DG1:BMMON" BASE='MFX:DG1:BMMON' EVR='MFX:DG1:BMMON:EVR' WAVE8='dg1ipm' - elif [ $1 == 'dg2ipm' ]; then + elif [[ $1 == 'dg2ipm' ]]; then IOC="IOC:MFX:DG2:BMMON" BASE='MFX:DG2:BMMON' EVR='MFX:DG2:BMMON:EVR' WAVE8='dg2ipm' - elif [ $1 == 'usrdio' ]; then + elif [[ $1 == 'usrdio' ]]; then IOC="IOC:MFX:USR:DIO" BASE='MFX:USR:DIO' EVR='MFX:USR:DIO:EVR' WAVE8='usrdio' fi -elif [ $hutch == 'xpp' ]; then - if [ $1 == 'diomono' ]; then +elif [[ $hutch == 'xpp' ]]; then + if [[ $1 == 'diomono' ]]; then IOC="IOC:XPP:IPM" BASE='XPP:MON:IPM:02' EVR='XPP:IPM:EVR' - elif [ $1 == 'decmono' ]; then + elif [[ $1 == 'decmono' ]]; then IOC="IOC:XPP:IPM" BASE='XPP:MON:IPM:01' EVR='XPP:IPM:EVR' - elif [ $1 == 'ipm2' ]; then + elif [[ $1 == 'ipm2' ]]; then IOC="IOC:XPP:SB2:BMMON" BASE='XPP:SB2:BMMON' EVR='XPP:SB2:BMMON:EVR' WAVE8='sb2bmmon' - elif [ $1 == 'ipm3' ]; then + elif [[ $1 == 'ipm3' ]]; then IOC="IOC:XPP:SB3:BMMON" BASE='XPP:SB3:BMMON' EVR='XPP:SB3:BMMON:EVR' WAVE8='sb3bmmon' - elif [ $1 == 'pim3' ]; then + elif [[ $1 == 'pim3' ]]; then IOC="IOC:XPP:IPM" BASE='XPP:SB3:IPM:02' EVR='XPP:IPM:EVR' - elif [ $1 == 'diodeU' ]; then + elif [[ $1 == 'diodeU' ]]; then IOC="IOC:XPP:IPM" BASE='XPP:USR:IPM:01' EVR='XPP:IPM:EVR' fi -elif [ $hutch == 'mec' ]; then - if [ $1 == 'ipm1' ]; then +elif [[ $hutch == 'mec' ]]; then + if [[ $1 == 'ipm1' ]]; then IOC="XRT:R33:IOC:39" BASE='MEC:HXM:IPM:01' EVR='XRT:R44:EVR:39' - elif [ $1 == 'hxm_pim' ]; then + elif [[ $1 == 'hxm_pim' ]]; then IOC="XRT:R33:IOC:39" BASE='MEC:HXM:PIM:01' EVR='XRT:R44:EVR:39' - elif [ $1 == 'pim2' ]; then + elif [[ $1 == 'pim2' ]]; then IOC="IOC:MEC:IMB02" BASE='MEC:XT2:PIM:02' EVR='MEC:XT2:EVR:01' - elif [ $1 == 'pim3' ]; then + elif [[ $1 == 'pim3' ]]; then IOC="IOC:MEC:IMB02" BASE='MEC:XT2:PIM:03' EVR='MEC:XT2:EVR:01' - elif [ $1 == 'tc1_imb1' ]; then + elif [[ $1 == 'tc1_imb1' ]]; then IOC="IOC:MEC:IPIMB01" EVR='MEC:TC1:EVR:01' BASE='MEC:TC1:IMB:01' - elif [ $1 == 'usr_imb1' ]; then + elif [[ $1 == 'usr_imb1' ]]; then IOC="IOC:MEC:IPIMB01" EVR='MEC:TC1:EVR:01' BASE='MEC:USR:IMB:01' - elif [ $1 == 'usr_imb2' ]; then + elif [[ $1 == 'usr_imb2' ]]; then IOC="IOC:MEC:IPIMB01" EVR='MEC:TC1:EVR:01' BASE='MEC:USR:IMB:02' - elif [ $1 == 'las_imb1' ]; then + elif [[ $1 == 'las_imb1' ]]; then IOC="IOC:MEC:IPIMB01" EVR='MEC:TC1:EVR:01' BASE='MEC:LAS:IMB:01' - elif [ $1 == 'las_imb2' ]; then + elif [[ $1 == 'las_imb2' ]]; then IOC="IOC:MEC:IPIMB01" EVR='MEC:TC1:EVR:01' BASE='MEC:LAS:IMB:02' - elif [ $1 == 'ipm2' ]; then + elif [[ $1 == 'ipm2' ]]; then IOC="IOC:MEC:XT2-1:BMMON" EVR="MEC:XT2-1:BMMON:EVR" BASE="MEC:XT2-1:BMMON" WAVE8='xt2-1bmmon' - elif [ $1 == 'ipm3' ]; then + elif [[ $1 == 'ipm3' ]]; then IOC="IOC:MEC:XT2-2:BMMON" EVR="MEC:XT2-2:BMMON:EVR" BASE="MEC:XT2-2:BMMON" @@ -240,11 +240,11 @@ fi # Attempt to read the :SUM PV and open a GUI if successful and exits if not. Uses wave8 or ipimb accordingly ipmGUI(){ - if caget ${BASE}:SUM > /dev/null 2>&1; then + if caget "$BASE":SUM > /dev/null 2>&1; then if [ ${#WAVE8} -gt 0 ]; then - /reg/g/pcds/pyps/apps/wave8/latest/wave8 --base $BASE --evr $EVR --ioc $IOC + /reg/g/pcds/pyps/apps/wave8/latest/wave8 --base "$BASE" --evr "$EVR" --ioc "$IOC" else - /reg/g/pcds/controls/pycaqt/ipimb/ipimb --base $BASE --ioc $IOC --evr $EVR + /reg/g/pcds/controls/pycaqt/ipimb/ipimb --base "$BASE" --ioc "$IOC" --evr "$EVR" fi else echo "Could not connect to ${BASE}. Exiting..." @@ -254,8 +254,8 @@ ipmGUI(){ # Get hutch name, if not given, using get_info get_hutch(){ if [ -z "$HUTCH" ]; then - hutch=`get_info --gethutch` - if [ $hutch = unknown_hutch ]; then + hutch=$(get_info --gethutch) + if [[ $hutch = unknown_hutch ]]; then echo 'unknown hutch, cannot use ipmConfigEpics script' exit 1 fi @@ -287,7 +287,7 @@ helpBld(){ # Attempt to caput values caput HFX:DG3:CVV:01:Stats2:EnableCallbacks 0 caput XCS:DG3:CVV:02:Stats2:EnableCallbacks 0 - # Check if actually set + # Check if actually set if [[ $(caget -nt HFX:DG3:CVV:01:Stats2:EnableCallbacks 2> /dev/null) == 0 ]] && [[ $(caget -nt XCS:DG3:CVV:02:Stats2:EnableCallbacks 2> /dev/null) == 0 ]]; then echo 'Turned off statsPlugin for XCS ipm3 and dio3' else @@ -334,10 +334,10 @@ done get_hutch if [ ${#BOXNAME} == 0 ]; then ipmList - printf 'Enter box name from above list:\n'; read BOXNAME + printf 'Enter box name from above list:\n'; read -r BOXNAME fi -ipmSetEnvPars $BOXNAME +ipmSetEnvPars "$BOXNAME" if [ $HELPDAQBLD -gt 0 ]; then helpBld else diff --git a/scripts/kinit_helper b/scripts/kinit_helper index bb7076ee..1af37d91 100755 --- a/scripts/kinit_helper +++ b/scripts/kinit_helper @@ -15,7 +15,7 @@ function kauth { } function afsauth { - # need to be in g-pcds afs grup + # need to be in g-pcds afs grup if ! pts membership g-pcds 2>&1 | grep -q "$(whoami)" then echo "You do not have permission to use afs. See https://confluence.slac.stanford.edu/display/PCDS/Onboarding+Staff+Members" diff --git a/scripts/makepeds b/scripts/makepeds index 203f9ebd..b2f1458d 100755 --- a/scripts/makepeds +++ b/scripts/makepeds @@ -1,6 +1,6 @@ #! /bin/bash -DIR=`dirname $(readlink -f $0)` +DIR=$(dirname "$(readlink -f "$0")") PATH=$PATH:$DIR usage() @@ -11,25 +11,25 @@ usage: $0 options Make a pedestal file for offline use OPTIONS: - -u|--user + -u|--user user (needs to be able to log into the s3df) - -p|--post + -p|--post add to elog post -t|--test do not deploy pedestals (epix10k only) - -r|--run + -r|--run runnumber for pedestal - -e|--experiment + -e|--experiment in case you do not want pedestals for the ongoing experiment - -O|--opal + -O|--opal make pedestals for Opals (default only cspad/EPIX detectors) - -Z|--zyla + -Z|--zyla make pedestals for Zyla (default only cspad/EPIX detectors) -R|--Rayonix make pedestals for Rayonix (please note that this is not the correct procedure for this detector) -U|--uxi make pedestals for Uxi/Icarus detector - -j|--jungfrau3 + -j|--jungfrau3 make pedestals for Jungfrau - 3 run version(default only cspad/EPIX detectors) -q|--queue queue for batch submisson @@ -39,19 +39,19 @@ OPTIONS: lasing off run for XTCAV -v|--validity_start validity range (set to -end) - -N|--nevents <#> + -N|--nevents <#> use this number of events (default 1000). Needed when using -c as original events are counted - -c|--eventcode + -c|--eventcode use events with eventcode set - -n|--noise_max <#> + -n|--noise_max <#> if you have created a noise file, then write pixel mask file for pixels with noise above #sigmas - -C|--noise_min <#> + -C|--noise_min <#> if noise filecreated, write pixel mask file for pixels with noise below xxx (currently integer only) - -m|--adu_min <#> + -m|--adu_min <#> write pixel mask file for pixels with pedestal below xxx (currently integer only) - -x|--adu_max <#> + -x|--adu_max <#> write pixel mask file for pixels with pedestal above xxx )currently integer only) - -i|--interactive + -i|--interactive start calibman. -r 0: show all darks, -r n: show runs (n-25) - 25 -d|--calibdir give path for alternative calibdir @@ -84,7 +84,7 @@ do shift ;; -L|--xtcav_lasingoff) - POSITIONAL+=" $1" + POSITIONAL+=("$1") elogMessage="Lasing off for XTCAV" shift ;; @@ -163,43 +163,43 @@ INTERACTIVE=${INTERACTIVE:=0} # also put 'xxx' (default q name) as S3DF so that even if no queue is given, # it goes to S3DF SDFQUEUES=('milano' 'roma' 'xxx') -for SDFQUEUE in ${SDFQUEUES[@]}; do - if [[ $QUEUE == $SDFQUEUE ]]; then +for SDFQUEUE in "${SDFQUEUES[@]}"; do + if [[ $QUEUE == "$SDFQUEUE" ]]; then S3DF=1 fi done if [[ $RUN == 0 ]]; then if [[ $INTERACTIVE == 0 ]]; then - printf "Please enter a run number: \n"; read RUN - set -- "$@" '--run ' $RUN + printf "Please enter a run number: \n"; read -r RUN + set -- "$@" '--run ' "$RUN" fi fi if [[ $EXP == 'xxx' ]]; then - HUTCH=`get_info --gethutch` - EXP=`get_info --exp --hutch $HUTCH` - set -- "$@" '--experiment ' $EXP + HUTCH=$(get_info --gethutch) + EXP=$(get_info --exp --hutch "$HUTCH") + set -- "$@" '--experiment ' "$EXP" else HUTCH=${EXP:0:3} fi if [[ $HOSTNAME =~ "sdf" ]]; then #echo $DIR/makepeds_psana $@ - $DIR/makepeds_psana $@ + "$DIR"/makepeds_psana "$@" else if [[ $USER =~ "opr" ]]; then - printf "Please enter user name (cannot run as from operator account): \n"; read USER + printf "Please enter user name (cannot run as from operator account): \n"; read -r USER fi - echo calling on SDF system: makepeds_psana $@ + echo calling on SDF system: makepeds_psana "$@" # We need to change paths here as the S3DF filesytem is completely independent if [ -v SDFDIR ]; then DIR=$SDFDIR else - DIR=`echo $DIR | sed 's/\/cds\/group\/pcds/\/sdf\/group\/lcls\/ds\/tools/g' | sed 's/\/reg\/g\/pcds/\/sdf\/group\/lcls\/ds\/tools/g'` + DIR=$(echo "$DIR" | sed 's/\/cds\/group\/pcds/\/sdf\/group\/lcls\/ds\/tools/g' | sed 's/\/reg\/g\/pcds/\/sdf\/group\/lcls\/ds\/tools/g') fi - echo ssh -Y $USER@s3dflogin ssh -Y psana "$DIR/makepeds_psana $@" - ssh -Y $USER@s3dflogin ssh -Y psana "$DIR/makepeds_psana $@" + echo ssh -Y "$USER"@s3dflogin ssh -Y psana "$DIR/makepeds_psana" "$@" + ssh -Y "$USER"@s3dflogin ssh -Y psana "$DIR/makepeds_psana" "$@" fi if [[ $HOSTNAME =~ "sdf" ]]; then @@ -208,11 +208,11 @@ else source pcds_conda fi -elog_par_post --file pedestal -e "$EXP" -r $RUN +elog_par_post --file pedestal -e "$EXP" -r "$RUN" #if this is a default pedestal run, then do not post as this is handled in takepeds -if [[ $elogMessage == 'DARK' ]] && [[ $ELOGTXT == '' ]] ; then - echo ---- Done processing pedestals for Run $RUN ----- +if [[ $elogMessage == 'DARK' ]] && [[ $ELOGTEXT == '' ]] ; then + echo ---- Done processing pedestals for Run "$RUN" ----- exit 0 fi @@ -223,21 +223,21 @@ fi PYCMD=LogBookPost.py echo -- Now posting special message to elog -- -echo -- $elogMessage -- +echo -- "$elogMessage" -- elogMessage+=$ELOGTEXT -if [[ `whoami` =~ "opr" ]]; then - echo $BINPATH $PYCMD -i "${HUTCH^^}" -u `whoami` -e "$EXP" -t DARK -r $RUN -m "$elogMessage" +if [[ $(whoami) =~ "opr" ]]; then + echo "$BINPATH" $PYCMD -i "${HUTCH^^}" -u "$(whoami)" -e "$EXP" -t DARK -r "$RUN" -m "$elogMessage" if [[ $HOSTNAME == 'cxi-monitor' ]]; then - $BINPATH $PYCMD -i "${HUTCH^^}" -u `whoami` -p pcds -e "$EXP" -t DARK -r $RUN -m "$elogMessage" -s 1& + $BINPATH $PYCMD -i "${HUTCH^^}" -u "$(whoami)" -p pcds -e "$EXP" -t DARK -r "$RUN" -m "$elogMessage" -s 1& else - $BINPATH $PYCMD -i "${HUTCH^^}" -u `whoami` -p pcds -e "$EXP" -t DARK -r $RUN -m "$elogMessage"& + $BINPATH $PYCMD -i "${HUTCH^^}" -u "$(whoami)" -p pcds -e "$EXP" -t DARK -r "$RUN" -m "$elogMessage"& fi else - echo $BINPATH $PYCMD -i "${HUTCH^^}" -e "$EXP" -t DARK -r $RUN -m "$elogMessage" + echo "$BINPATH" $PYCMD -i "${HUTCH^^}" -e "$EXP" -t DARK -r "$RUN" -m "$elogMessage" if [[ $HOSTNAME == 'cxi-monitor' ]]; then - $BINPATH $PYCMD -i "${HUTCH^^}" -e "$EXP" -t DARK -r $RUN -m "$elogMessage" -s 1& + $BINPATH $PYCMD -i "${HUTCH^^}" -e "$EXP" -t DARK -r "$RUN" -m "$elogMessage" -s 1& else - $BINPATH $PYCMD -i "${HUTCH^^}" -e "$EXP" -t DARK -r $RUN -m "$elogMessage"& + $BINPATH $PYCMD -i "${HUTCH^^}" -e "$EXP" -t DARK -r "$RUN" -m "$elogMessage"& fi fi diff --git a/scripts/makepeds_psana b/scripts/makepeds_psana index 9d60bf8d..df117c08 100755 --- a/scripts/makepeds_psana +++ b/scripts/makepeds_psana @@ -13,19 +13,19 @@ usage: $0 options Make a pedestal file for offline use OPTIONS: - -r|--run + -r|--run runnumber for pedestal - -e|--experiment + -e|--experiment in case you do not want pedestals for the ongoing experiment - -O|--opal + -O|--opal make pedestals for Opals (default only cspad/EPIX detectors) - -Z|--zyla + -Z|--zyla make pedestals for Zyla (default only cspad/EPIX detectors) -R|--Rayonix make pedestals for Rayonix (please note that this is not the correct procedure for this detector) -U|--uxi make pedestals for Uxi detectors - -j|--jungfrau3 + -j|--jungfrau3 make pedestals for Jungfrau - 3 run version(default only cspad/EPIX detectors) -q|--queue queue for batch submisson @@ -35,19 +35,19 @@ OPTIONS: lasing off run for XTCAV -v|--validity_start validity range (set to -end) - -N|--nevents <#> + -N|--nevents <#> use this number of events (default 1000). Needed when using -c as original events are counted - -c|--eventcode + -c|--eventcode use events with eventcode set - -n|--noise_max <#> + -n|--noise_max <#> if you have created a noise file, then write pixel mask file for pixels with noise above #sigmas - -C|--noise_min <#> + -C|--noise_min <#> if noise filecreated, write pixel mask file for pixels with noise below xxx (currently integer only) - -m|--adu_min <#> + -m|--adu_min <#> write pixel mask file for pixels with pedestal below xxx (currently integer only) - -x|--adu_max <#> + -x|--adu_max <#> write pixel mask file for pixels with pedestal above xxx )currently integer only) - -i|--interactive + -i|--interactive start calibman. -r 0: show all darks, -r n: show runs (n-25) - 25 -d|--calibdir give path for alternative calibdir @@ -119,7 +119,7 @@ xtcav_dark() else tmpScript=$(mktemp -p "$WORKDIR" xtcav_dark_tmpXXXXX.sh) chmod u+x "$tmpScript" - printf '#!/bin/bash\nsource $SIT_ENV_DIR/manage/bin/psconda.sh\n' > "$tmpScript" + printf "#!/bin/bash\nsource %s/manage/bin/psconda.sh\n" "$SIT_ENV_DIR" > "$tmpScript" CMD="xtcavDark $EXP $RUN" printf '%s\n' "${CMD}" >> "$tmpScript" xtcavCmd="sbatch --exclusive --account lcls:$EXP -p $QUEUE -o $WORKDIR/xtcav_${EXP}_Run${RUN}_%J.out $tmpScript" @@ -154,7 +154,7 @@ xtcav_lasOff() else tmpScript=$(mktemp -p "$WORKDIR" xtcav_dark_tmpXXXXX.sh) chmod u+x "$tmpScript" - printf '#!/bin/bash\nsource $SIT_ENV_DIR/manage/bin/psconda.sh\n' > "$tmpScript" + printf "#!/bin/bash\nsource %s/manage/bin/psconda.sh\n" "$SIT_ENV_DIR" > "$tmpScript" CMD="xtcavLasingOff $EXP $RUN" printf '%s\n' "${CMD}" >> "$tmpScript" xtcavCmd="sbatch --exclusive --account lcls:$EXP -p $QUEUE -o $WORKDIR/xtcav_${EXP}_Run${RUN}_%J.out $tmpScript" @@ -177,11 +177,12 @@ xtcav_lasOff() exit } -# Arg: DETECTOR class. This could be a comma-separated list, but we're +# Arg: DETECTOR class. This could be a comma-separated list, but we're # matching it in the config file as a string. get_config() { awk 'BEGIN{n=0;}/'"$1"' \{/{n=1;next;}/\}/{n=0;next;}{if(n)print;}' <"$CFGFILE" >/tmp/script.$$ + # shellcheck disable=SC1090 source /tmp/script.$$ rm /tmp/script.$$ #overwrite if argument is passed @@ -213,8 +214,7 @@ deploy_geometry() fi echo calling "$CMD" - $CMD - if [ "$?" != "0" ]; then + if $CMD; then echo Error: Geometry not deployed! else echo Geometry now deployed. @@ -239,8 +239,7 @@ deploy_gain() CMD=$CMD' -x :dir='$XTCDIR'/:stream=0-79' echo calling "$CMD" - $CMD - if [ "$?" != "0" ]; then + if $CMD; then echo Error: Gain file not deployed! else echo Gain file deployed. @@ -390,8 +389,8 @@ NUMBUNCH=${NUMBUNCH:=1} #one setting to run each process on an own server (currently faster) or not (if we had to use reservations) EXCLUSIVE=0 -if [ $RUN == 0 ]; then - if [ $INTERACTIVE -ne 1 ]; then +if [[ $RUN == 0 ]]; then + if [[ $INTERACTIVE -ne 1 ]]; then printf "Please enter a run number HERE: \n"; read -r RUN fi fi @@ -399,7 +398,7 @@ fi PCDSDIR='/sdf/group/lcls/ds/tools/' SIT_ENV_DIR="/sdf/group/lcls/ds/ana/sw" -if [ $EXP == 'xxx' ]; then +if [[ $EXP == 'xxx' ]]; then echo 'no experiment passed!!!' HUTCH=$($PCDSDIR/engineering_tools/latest-released/scripts/get_info --gethutch) echo HUTCH "$HUTCH" @@ -421,7 +420,7 @@ fi LCLS2_HUTCHES="rix, tmo, ued" if echo "$LCLS2_HUTCHES" | grep -iw "$HUTCH" > /dev/null; then echo "This is a LCLS-II experiment" - + SIT_ENV_DIR=$SIT_ENV_DIR'/conda2/' LCLS2=1 else @@ -430,7 +429,7 @@ else fi source $SIT_ENV_DIR/manage/bin/psconda.sh -#if you don't pass the queue, it'll run interactively +#if you don't pass the queue, it'll run interactively if [[ $QUEUE == 'xxx' ]]; then RUNLOCAL=1 fi @@ -442,8 +441,8 @@ ARG=' -n '$NUMEVT' -Z 1000000 -U 1000000 -z 1000000 -u 1000000 ' # find xtc directory # look for xtc w/o in progress if not using live mode. TOBEIMPLEMENTED ########### -RUNSTR=$(printf '%04d' $RUN) -RUNSTR=$EXP-r$RUNSTR*.xtc +RUNSTR=$(printf '%04d' "$RUN") +RUNSTR="$EXP-r$RUNSTR*.xtcx" XTCDIR=/sdf/data/lcls/ds/"$HUTCH"/"$EXP"/xtc # If inprogress files use FFB location if compgen -G "$XTCDIR/$RUNSTR.inprogress" > /dev/null; then @@ -459,7 +458,7 @@ echo "Use XTC files from $XTCDIR." ########### # deduce calibdir. ########### -if [ $CALIBDIR != 'xxx' ]; then +if [[ $CALIBDIR != 'xxx' ]]; then ARG=$ARG' -c '$CALIBDIR JFARG=' -C '$CALIBDIR else @@ -489,17 +488,18 @@ fi if [ ! -w "$WORKDIR" ]; then echo 'Typical directory to store calib logfiles & results is not writeable, will attempt to work from /tmp, but things may fail' WORKDIR='/tmp' -fi +fi cd "$WORKDIR" ###################### # work on the XTCAV ###################### -if [ $XTCAV == 1 ]; then +if [[ $XTCAV == 1 ]]; then xtcav_dark fi -if [ $XTCAV == 2 ]; then + +if [[ $XTCAV == 2 ]]; then xtcav_lasOff fi ###################### @@ -509,15 +509,15 @@ fi ########### # few generic parameters ########### -if [ $INTERACTIVE == 1 ]; then +if [[ $INTERACTIVE == 1 ]]; then echo 'now calling calibman (GUI) - switch to old release for now' source /reg/g/psdm/etc/psconda.sh.old calibman exit fi -if [ $CALIBCODE -ne 0 ]; then - if [ $NUMEVT -le 1000 ]; then +if [[ $CALIBCODE -ne 0 ]]; then + if [[ $NUMEVT -le 1000 ]]; then NUMEVT=1000000 fi ARG=$ARG' -f '$CALIBCODE @@ -530,7 +530,7 @@ fi # ARG=$ARG' -q '$QUEUE #fi -if [ $DEPLOY == 1 ]; then +if [[ $DEPLOY == 1 ]]; then ARG=$ARG' -D ' fi @@ -538,7 +538,7 @@ fi CREATE_TIME=$(date '+%m_%d_%Y_%H:%M:%S') printf -v RUNSTR "%04g" "$RUN" -echo Check detectors: +echo Check detectors: ls -ltr "$XTCDIR"/*r"$RUNSTR"*s*xtc* if [[ $LCLS2 -gt 0 ]]; then @@ -552,12 +552,12 @@ echo 'XTC files contain:' cat /tmp/detnames_"$EXP"_"$CREATE_TIME" echo "-----------------------" -#### +#### # Section for LCLS2 detectors. #### if [[ $LCLS2 -gt 0 ]]; then #### - # epix100 in LCLS2 related stuff. + # epix100 in LCLS2 related stuff. #### #check if epix100 detectors are present HAVE_EPIX100=$(grep -c epix100 /tmp/detnames_"$EXP"_"$CREATE_TIME") @@ -598,7 +598,7 @@ if [[ $LCLS2 -gt 0 ]]; then CMD="epix10ka_pedestals_calibration -d $EPIX10K -e $EXP -r $RUN --stepnum $calibcycle --stepmax $nextcycle -L INFO -x dir=$XTCDIR" echo "---------------EPIX10K PEDESTALS FOR CYCLE $calibcycle --------------------" if [[ $RUNLOCAL != 1 ]]; then - tmpScript=$(mktemp -p $WORKDIR epix10ka_pedestals_tmpXXXXX.sh) + tmpScript=$(mktemp -p "$WORKDIR" epix10ka_pedestals_tmpXXXXX.sh) #trap "rm -f $tmpScript" EXIT chmod u+x "$tmpScript" printf '#!/bin/bash\n' > "$tmpScript" @@ -616,7 +616,7 @@ if [[ $LCLS2 -gt 0 ]]; then THISJOBID=$(echo "$SUBMISSION" | awk '{print $4}') JOBIDS+=( "$THISJOBID" ) NJOBS=$((NJOBS+1)) - else + else echo "$cmd" $CMD fi @@ -634,7 +634,7 @@ if [[ $LCLS2 -gt 0 ]]; then done echo 'All jobs finished' # and now check that none of the jobs have existed with an error code: - # currently, the epix10k jobs print DONE at the end. + # currently, the epix10k jobs print DONE at the end. # Second check necessary as jobs can fail without printing an exit code to the logfile for JOBID in "${ALLJOBIDS[@]}"; do echo "Checking job $JOBID" @@ -644,22 +644,22 @@ if [[ $LCLS2 -gt 0 ]]; then NFAILEDJOBS=$((NFAILEDJOBS+1)) fi done - + fi echo "---------------EPIX10K PEDESTALS CALCULATED NOW DEPLOY --------------------" - if [ $DEPLOY == 1 ]; then + if [[ $DEPLOY == 1 ]]; then if [ $NFAILEDJOBS -gt 0 ]; then read -r -p "$NFAILEDJOBS of the calibration tasks failed, do you want to continue anyways (y/n)?" if [ "$REPLY" != "y" ];then exit 1 fi fi - + for EPIX10K in $DETNAMES; do CMD="epix10ka_deploy_constants -D -d $EPIX10K -e $EXP -r $RUN -L INFO -x :dir=$XTCDIR" - echo 'setting validity....' $VALSTR - if [ $VALSTR != 'xxx' ]; then + echo "setting validity...$VALSTR" + if [[ $VALSTR != 'xxx' ]]; then CMD=$CMD' -t '$VALSTR fi echo "$cmd" @@ -669,7 +669,7 @@ if [[ $LCLS2 -gt 0 ]]; then echo 'Print Information about batch jobs' JOBIDSTR='' for JOBID in "${ALLJOBIDS[@]}"; do - if [[ $JOBIDSTR != '' ]]; then + if [[ $JOBIDSTR != '' ]]; then JOBIDSTR=$JOBIDSTR',' fi JOBIDSTR=$JOBIDSTR$JOBID @@ -697,7 +697,7 @@ fi #check if jungfrau detectors are present HAVE_JUNGFRAU=$(grep -c Jungfrau /tmp/detnames_"$EXP"_"$CREATE_TIME") if [[ ( $HAVE_JUNGFRAU -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) && ( $WANT_RAYONIX -eq 0 ) && ( $WANT_UXI -eq 0 ) ]]; then - + DETNAMES=$(grep Jungfrau /tmp/detnames_"$EXP"_"$CREATE_TIME" | awk 'BEGIN { FS = "|"}; {print $1}' | paste -d " " -s) DSNAME='exp='$EXP':run='$RUN':smd:stream=0-79' @@ -711,7 +711,7 @@ if [[ ( $HAVE_JUNGFRAU -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) & #default arguments. JFARG=$JFARG' -d '$DSNAME - if [ $CALIBCODE -ne 0 ]; then + if [[ $CALIBCODE -ne 0 ]]; then JFARG=$JFARG' -c '$CALIBCODE' --evstep '$NUMEVT fi JFARG=$JFARG' --events '$NUMEVT @@ -730,7 +730,7 @@ if [[ ( $HAVE_JUNGFRAU -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) & JOBIDS=() NJOBS=0 fi - + for JUNGFRAU in $DETNAMES; do echo "jungfrau loop $JUNGFRAU -- $RUNLOCAL" CMD="jungfrau_dark_proc $JFARG -s $JUNGFRAU" @@ -738,25 +738,27 @@ if [[ ( $HAVE_JUNGFRAU -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) & for calibcycle in {0..2}; do if [ -v OLD_JUNGFRAU ]; then CMDC=$CMD - elif [ $CALIBCODE -eq 0 ]; then + elif [[ $CALIBCODE -eq 0 ]]; then CMDC=$CMD' --stepnum '$calibcycle else CMDC=$CMD fi if [[ $RUNLOCAL != 1 ]]; then - tmpScript=$(mktemp -p $WORKDIR jungfrau_multi_tmpXXXXX.sh) + tmpScript=$(mktemp -p "$WORKDIR" jungfrau_multi_tmpXXXXX.sh) #trap "rm -f $tmpScript" EXIT chmod u+x "$tmpScript" printf '#!/bin/bash\n' > "$tmpScript" - printf 'source %s/manage/bin/psconda.sh\n' "${SIT_ENV_DIR}" >> "$tmpScript" - printf 'echo $HOSTNAME\n' >> "$tmpScript" - printf '%s\n' "${CMDC}" >> "$tmpScript" + { + printf 'source %s/manage/bin/psconda.sh\n' "$SIT_ENV_DIR" + printf "echo %s\n" "$HOSTNAME" + printf '%s\n' "${CMDC}" + } >> "tmpScript" if [[ $EXCLUSIVE == 1 ]]; then jfCmd="sbatch --exclusive --account lcls:$EXP -p $QUEUE -o $WORKDIR/jungfrau_${EXP}_RUN${RUN}_%J.out $tmpScript" else jfCmd="sbatch --mem 8GB --cpus-per-task 1 --account lcls:$EXP -p $QUEUE -o $WORKDIR/jungfrau_${EXP}_RUN${RUN}_%J.out $tmpScript" fi - echo "run in queue: $jfCmd" + echo "run in queue: $jfCmd" SUBMISSION=$($jfCmd) check_for_submit_error echo "$SUBMISSION" @@ -770,7 +772,7 @@ if [[ ( $HAVE_JUNGFRAU -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) & if [ -v OLD_JUNGFRAU ]; then break fi - if [ $CALIBCODE -ne 0 ]; then + if [[ $CALIBCODE -ne 0 ]]; then break fi done @@ -781,7 +783,7 @@ if [[ ( $HAVE_JUNGFRAU -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) & if [[ $RUNLOCAL != 1 ]]; then echo 'Wait for 1/2 minutes before checking jobs:' sleep 30 - echo Running $NJOBS jobs are PIDS: "${JOBIDS[@]}" + echo "Running $NJOBS jobs are PIDS: ${JOBIDS[*]}" until check_running_jobs; do echo 'Checking again in 10s' sleep 10 @@ -799,8 +801,8 @@ if [[ ( $HAVE_JUNGFRAU -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) & fi #Now deploy. - if [ $DEPLOY == 1 ]; then - if [ $NFAILEDJOBS -gt 0 ]; then + if [[ $DEPLOY == 1 ]]; then + if [[ $NFAILEDJOBS -gt 0 ]]; then read -r -p "$NFAILEDJOBS of the calibration tasks failed, do you want to continue (y/n)?" if [ "$REPLY" != "y" ];then exit 1 @@ -809,8 +811,8 @@ if [[ ( $HAVE_JUNGFRAU -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) & for JUNGFRAU in $DETNAMES; do #this is also where -t should be used, just as for the validity range CMD="jungfrau_deploy_constants -D -d $JUNGFRAU -e $EXP -r $RUN -x :dir=$XTCDIR" - if [ $VALSTR != 'xxx' ]; then - # this does not work before ana-..... + if [[ $VALSTR != 'xxx' ]]; then + # this does not work before ana-..... #CMD=$CMD' -t '$VALSTR'-end' CMD=$CMD' -t '$VALSTR fi @@ -839,7 +841,7 @@ if [[ ( $HAVE_EPIX10K -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) && JOBIDS=() NJOBS=0 fi - + for EPIX10K in $DETNAMES; do echo "Epix10ka name for $EXP is: $EPIX10K" ##run all at once - do not use @@ -850,7 +852,7 @@ if [[ ( $HAVE_EPIX10K -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) && CMD="epix10ka_pedestals_calibration -d $EPIX10K -e $EXP -r $RUN -c $calibcycle -x :dir=$XTCDIR:live:stream=0-79 -L INFO" echo "---------------EPIX10K PEDESTALS FOR CYCLE $calibcycle --------------------" if [[ $RUNLOCAL != 1 ]]; then - tmpScript=$(mktemp -p $WORKDIR epix10ka_pedestals_tmpXXXXX.sh) + tmpScript=$(mktemp -p "$WORKDIR" epix10ka_pedestals_tmpXXXXX.sh) #trap "rm -f $tmpScript" EXIT chmod u+x "$tmpScript" printf '#!/bin/bash\n' > "$tmpScript" @@ -868,7 +870,7 @@ if [[ ( $HAVE_EPIX10K -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) && THISJOBID=$(echo "$SUBMISSION" | awk '{print $4}') JOBIDS+=( "$THISJOBID" ) NJOBS=$((NJOBS+1)) - else + else echo "$CMD" $CMD fi @@ -878,14 +880,14 @@ if [[ ( $HAVE_EPIX10K -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) && if [[ $RUNLOCAL != 1 ]]; then echo 'Wait for 1/2 minute before checking jobs:' sleep 30 - echo Running $NJOBS jobs are PIDS: "${JOBIDS[@]}" + echo "Running $NJOBS jobs are PIDS: ${JOBIDS[*]}" until check_running_jobs; do echo 'Checking again in 10s' sleep 10 done echo 'All jobs finished' # and now check that none of the jobs have existed with an error code: - # currently, the epix10k jobs print DONE at the end. + # currently, the epix10k jobs print DONE at the end. # Second check necessary as jobs can fail without printing an exit code to the logfile NFAILEDJOBS=0 for JOBID in "${ALLJOBIDS[@]}"; do @@ -895,12 +897,12 @@ if [[ ( $HAVE_EPIX10K -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) && elif ! grep -q 'DONE' "$WORKDIR"/*"$JOBID".out; then NFAILEDJOBS=$((NFAILEDJOBS+1)) fi - done + done fi echo "---------------EPIX10K PEDESTALS CALCULATED NOW DEPLOY --------------------" - if [ $DEPLOY == 1 ]; then - if [ $NFAILEDJOBS -gt 0 ]; then + if [[ $DEPLOY == 1 ]]; then + if [[ $NFAILEDJOBS -gt 0 ]]; then read -r -p "$NFAILEDJOBS of the calibration tasks failed, do you want to continue anyways (y/n)?" if [ "$REPLY" != "y" ];then exit 1 @@ -909,8 +911,8 @@ if [[ ( $HAVE_EPIX10K -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) && for EPIX10K in $DETNAMES; do CMD="epix10ka_deploy_constants -D -d $EPIX10K -e $EXP -r $RUN -L INFO -x :dir=$XTCDIR:stream=0-79" - if [ $VALSTR != 'xxx' ]; then - echo 'setting validity....' $VALSTR + if [[ $VALSTR != 'xxx' ]]; then + echo "setting validity...$VALSTR" CMD=$CMD' -t '$VALSTR fi echo "$CMD" @@ -920,7 +922,7 @@ if [[ ( $HAVE_EPIX10K -ge 1 ) && ( $WANT_ZYLA -eq 0 ) && ( $WANT_OPAL -eq 0 ) && echo 'Print Information about batch jobs' JOBIDSTR='' for JOBID in "${ALLJOBIDS[@]}"; do - if [[ $JOBIDSTR != '' ]]; then + if [[ $JOBIDSTR != '' ]]; then JOBIDSTR=$JOBIDSTR',' fi JOBIDSTR=$JOBIDSTR$JOBID @@ -939,7 +941,7 @@ fi # Make list of detectors to treat with calibrun ########### -#check if detectors are present +#check if detectors are present HAVE_EPIX=$(grep -c Epix100 /tmp/detnames_"$EXP"_"$CREATE_TIME") HAVE_CSPAD=$(grep -c Cspad /tmp/detnames_"$EXP"_"$CREATE_TIME") HAVE_ZYLA=$(grep -c Zyla /tmp/detnames_"$EXP"_"$CREATE_TIME") @@ -1011,10 +1013,10 @@ if [[ ( $HAVE_RAYONIX -ge 1 ) && ( $WANT_RAYONIX -ge 1 ) ]]; then if [ $SPECIFIED_CUTS -eq -4 ]; then DETS="$DETS Rayonix" else - DETS='Rayonix' + DETS='Rayonix' fi ARG=$ARG' --zeropeds' - + DETNAMES=$(grep Rayonix /tmp/detnames_"$EXP"_"$CREATE_TIME" | awk 'BEGIN { FS = "|"}; {print $1}' | paste -d " " -s) for RAYONIX in $DETNAMES; do deploy_geometry "$RAYONIX" @@ -1037,7 +1039,7 @@ echo "for the following detectors: $DETS" for MYDET in $DETS; do #set thresholds for the detector in question #ADU minimum, maximum - get_config $MYDET + get_config "$MYDET" LOCARG=$ARG' --thr_int_min '$ADUMIN' --thr_int_max '$ADUMAX' --thr_rms_min '$NOISESIGMIN' --thr_rms_max '$NOISESIGMAX #this was likely to work with runs where the zyla rate was < readout rate.... @@ -1045,7 +1047,7 @@ for MYDET in $DETS; do LOCARG=$LOCARG' -m 100' fi - if [ $VALSTR != 'xxx' ]; then + if [[ $VALSTR != 'xxx' ]]; then LOCARG=$LOCARG' -v '$VALSTR'-end' fi diff --git a/scripts/motor-expert-screen b/scripts/motor-expert-screen index fd5800c1..ca92cba5 100755 --- a/scripts/motor-expert-screen +++ b/scripts/motor-expert-screen @@ -17,9 +17,9 @@ if [[ ($1 == "--help") || ($1 == "-h") || (-z $1) ]]; then exit 0 fi -shift $(($OPTIND - 1)) +shift $((OPTIND - 1)) -PREFIX=`echo $1 | cut -d . -f 1` +PREFIX=$(echo "$1" | cut -d . -f 1) # Setup edm environment source /reg/g/pcds/setup/epicsenv-3.14.12.sh @@ -36,7 +36,7 @@ isbeckhoff=false # Choose title so we can move the right window. # If this script hangs later, titles probably changed. -rtyp=`caget -t $PREFIX.RTYP` > /dev/null 2>&1 +rtyp=$(caget -t "$PREFIX".RTYP) > /dev/null 2>&1 if [ "${rtyp}" == 'xps8p' ]; then title='Newport XPS Positioner' elif [ "${rtyp}" == 'ims' ]; then @@ -45,16 +45,14 @@ elif [ "${rtyp}" == 'motor' ]; then # Check to see if this is a Beckhoff axis # caget will return exit code 0 if :PLC:nErrorId_RBV exists, # we set isbeckhoff based on this. - caget "${PREFIX}:PLC:nErrorId_RBV" > /dev/null 2>&1 - if [ $? -eq 0 ]; then + if caget "${PREFIX}:PLC:nErrorId_RBV" > /dev/null 2>&1; then title="Typhos Suite - ${PREFIX}" isbeckhoff=true; else title='Aerotech motor' fi else - caget "$PREFIX.PN" > /dev/null 2>&1 - if [ $? -eq 0 ]; then + if caget "$PREFIX.PN" > /dev/null 2>&1; then title='IMS Motor Control -- Main' else title='IMS Motor Control' @@ -65,16 +63,16 @@ fi # if xdotool is not installed, the move window commands will skip # Check already open windows -oldwins=`xdotool search --onlyvisible --maxdepth 2 --all --name "$title" 2> /dev/null` +oldwins=$(xdotool search --onlyvisible --maxdepth 2 --all --name "$title" 2> /dev/null) # Open new window if [ ${isbeckhoff} == true ]; then - motor-typhos ${PREFIX} > /dev/null 2>&1 & + motor-typhos "$PREFIX" > /dev/null 2>&1 & elif [ "${rtyp}" == 'xps8p' ]; then # If we have a Newport motor, we need to parse the PV to get the macro # substitutions for the edm screen - base=`echo $PREFIX | cut -d':' -f 1,2,3` - num=`echo $PREFIX | cut -d':' -f 4` + base=$(echo "$PREFIX" | cut -d':' -f 1,2,3) + num=$(echo "$PREFIX" | cut -d':' -f 4) if [ "$num" -ge 1 ] && [ "$num" -le 8 ]; then ext=0108 elif [ "$num" -ge 9 ] && [ "$num" -le 16 ]; then @@ -83,7 +81,7 @@ elif [ "${rtyp}" == 'xps8p' ]; then ext=1724 elif [ "$num" -ge 25 ] && [ "$num" -le 32 ]; then ext=2532 - elif [ "$num" -ge 33 ] && [ "$num" -le 40]; then + elif [ "$num" -ge 33 ] && [ "$num" -le 40 ]; then ext=3340 else # If something went wrong we'll be missing some boring things @@ -93,13 +91,12 @@ elif [ "${rtyp}" == 'xps8p' ]; then elif [ "${rtyp}" == 'mmca' ]; then # MMC-100 axis edm -x -eolc -m "MOTOR=$PREFIX" mmc_main.edl > /dev/null 2>&1 & elif [ "${rtyp}" == 'motor' ]; then - caget "$PREFIX:PN" > /dev/null 2>&1 - if [ $? -eq 0 ]; then + if caget "$PREFIX:PN" > /dev/null 2>&1; then /reg/g/pcds/package/epics/3.14//modules/pcds_motion/${OLD_VERSION}/launch-motor.sh "$PREFIX" > /dev/null 2>&1 & else # smaracts have "motor" rtyp, so we catch them with the PREFIX or with smaract specific pvs if [[ $PREFIX == *"MCS2"* || $(caget "$PREFIX:PTYPE_RBV" > /dev/null 2>&1) -eq 0 ]]; then - enc=$(caget $PREFIX.UEIP) + enc=$(caget "$PREFIX".UEIP) if [[ $enc == *"Yes"* ]]; then edm -x -eolc -m "MOTOR=$PREFIX" mcs2_main.edl > /dev/null 2>&1 & else @@ -120,13 +117,13 @@ fi # Accumulate all windows sleep 2 # Crudely give the new window enough time to load -newwins=`xdotool search --onlyvisible --maxdepth 2 --all --sync --name "$title" 2> /dev/null` +newwins=$(xdotool search --onlyvisible --maxdepth 2 --all --sync --name "$title" 2> /dev/null) # Find the id of the new window for new in $newwins; do foundMatch=0 for old in $oldwins; do - if [ $new == $old ]; then + if [[ $new == "$old" ]]; then foundMatch=1 break fi @@ -138,7 +135,7 @@ for new in $newwins; do done # Get window location, dimensions -geom=`xdotool getwindowgeometry $id 2> /dev/null` +geom=$(xdotool getwindowgeometry "$id" 2> /dev/null) locxy=${geom#*Position: } locxy=${locxy%% *} winx=${locxy%,*} @@ -149,17 +146,17 @@ xwidth=${sizexy%x*} ywidth=${sizexy#*x} # Get mouse position -read x y s w <<<$(xdotool getmouselocation 2> /dev/null) -xpos=`echo $x | cut -d':' -f 2` -ypos=`echo $y | cut -d':' -f 2` +read -r x y s w <<<"$(xdotool getmouselocation 2> /dev/null)" +xpos=$(echo "$x" | cut -d':' -f 2) +ypos=$(echo "$y" | cut -d':' -f 2) -if [ -z $xpos ]; then +if [[ -z $xpos ]]; then exit # Check if mouse is already on the window. In this case, we wouldn't move it. -elif [ "$xpos" -lt "$winx" ] || [ "$xpos" -gt $(( ${winx} + ${xwidth} )) ] || [ "$ypos" -lt "$winy" ] || [ "$ypos" -gt $(( ${winy} + ${ywidth} )) ]; then +elif [ "$xpos" -lt "$winx" ] || [ "$xpos" -gt $((winx + xwidth)) ] || [ "$ypos" -lt "$winy" ] || [ "$ypos" -gt $((winy + ywidth)) ]; then # Adjust xpos and ypos so center of window aligns with cursor. - xpos=$(( ${xpos} - ( ${xwidth} / 2 ) )) - ypos=$(( ${ypos} - ( ${ywidth} / 2 ) )) + xpos=$((xpos - (xwidth / 2))) + ypos=$((ypos - (ywidth / 2))) # Finally, move the window to our cursor. - xdotool windowmove $id $xpos $ypos 2> /dev/null + xdotool windowmove "$id" "$xpos" "$ypos" 2> /dev/null fi diff --git a/scripts/motor-typhos b/scripts/motor-typhos index e3453142..04bed80e 100755 --- a/scripts/motor-typhos +++ b/scripts/motor-typhos @@ -14,7 +14,7 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then exit 0 fi -PREFIX=`echo $1 | cut -d . -f 1` +PREFIX=$(echo "$1" | cut -d . -f 1) if [ -z "${PREFIX}" ]; then usage; @@ -24,9 +24,7 @@ fi # Use the latest tagged environment source /reg/g/pcds/pyps/conda/pcds_conda -caget "${PREFIX}:PLC:nErrorId_RBV" > /dev/null 2>&1 - -if [ $? -eq 0 ]; then +if caget "${PREFIX}:PLC:nErrorId_RBV" > /dev/null 2>&1; then echo "* This looks like a Beckhoff axis." DEVICE_CLASS="pcdsdevices.epics_motor.BeckhoffAxis" NAME="${PREFIX}" # maybe we can do better? @@ -39,4 +37,4 @@ fi TYPHOS_ARGS="${DEVICE_CLASS}[{'prefix':'${PREFIX}','name':'${NAME}'}]" echo "* Launching typhos with arguments: ${TYPHOS_ARGS}" echo "* This may take a bit, please wait..." -typhos ${TYPHOS_ARGS} > /dev/null 2>&1 & +typhos "$TYPHOS_ARGS" > /dev/null 2>&1 & diff --git a/scripts/motorInfo b/scripts/motorInfo index c65c5fe8..4da9360c 100755 --- a/scripts/motorInfo +++ b/scripts/motorInfo @@ -24,8 +24,8 @@ fi while getopts "f:s:e:" OPTION do case $OPTION in - f) - PVFIELDS=`echo $OPTARG | sed s/','/' '/g` + f) + PVFIELDS=${OPTARG//,/} ;; s) STARTTIME=$OPTARG @@ -33,109 +33,114 @@ do e) ENDTIME=$OPTARG ;; + *) + echo "Invalid option \"$OPTION\" provided" + usage + exit 1 + ;; esac done -shift $(($OPTIND - 1)) +shift $((OPTIND - 1)) if [ $# -lt 2 ]; then usage exit fi -MOTOR_PV=`echo $1 | cut -d . -f 1` -if [[ $1 == $MOTOR_PV ]]; then +MOTOR_PV=$(echo "$1" | cut -d . -f 1) +if [[ $1 == "$MOTOR_PV" ]]; then FIELD='' else - echo 1: $1 - echo MOTOR_PV $MOTOR_PV - FIELD=`echo $1 | cut -d . -f 2` + echo "1: $1" + echo "MOTOR_PV: $MOTOR_PV" + FIELD=$(echo "$1" | cut -d . -f 2) fi source /reg/g/pcds/setup/pcds_shortcuts.sh if [[ $PVFIELDS == '' ]] && [[ "$2" != *pmgr* ]]; then - IOC_DIR='/reg/g/pcds/epics/'`find_pv $MOTOR_PV | grep DIR | grep ims | awk '{print $2}'`'/build/autosave' - PVLIST=`grep $MOTOR_PV $IOC_DIR/*req` + IOC_DIR='/reg/g/pcds/epics/'$(find_pv "$MOTOR_PV" | grep DIR | grep ims | awk '{print $2}')'/build/autosave' + PVLIST=$("grep $MOTOR_PV $IOC_DIR/*req") for pv in $PVLIST; do - PVFIELDS=`echo $pv | awk -F "$MOTOR_PV" '{ print $2 }'`' '$PVFIELDS + PVFIELDS=$(echo "$pv" | awk -F "$MOTOR_PV" '{ print $2 }')' '$PVFIELDS done fi -if [ $2 == 'autosave' ]; then - IOC_DIR='/reg/d/iocData/'`find_pv $MOTOR_PV | grep IOC: | head -n 1 | awk '{print $2}'`'/autosave' +if [[ $2 == 'autosave' ]]; then + IOC_DIR='/reg/d/iocData/'$(find_pv "$MOTOR_PV" | grep IOC: | head -n 1 | awk '{print $2}')'/autosave' - files=`ls -t $IOC_DIR/*sav_1*` + files=$(ls -t "$IOC_DIR"/*sav_1*) for field in $PVFIELDS; do if [[ "$field" == *RBV* ]] || [[ "$field" == *VAL* ]] || [[ "$field" == *DESC* ]]; then continue fi - echo 'Looking at the autosave history for: ' $MOTOR_PV$field + echo "Looking at the autosave history for: $MOTOR_PV$field" same_value_dat='now' - currVal=`caget -t $MOTOR_PV$field` - currValN=`caget -tn $MOTOR_PV$field` + currVal=$(caget -t "$MOTOR_PV$field") + currValN=$(caget -tn "$MOTOR_PV$field") for file in $files; do - autoVal=`grep $MOTOR_PV$field' ' $file | awk {'print $2'}` - if [[ $autoVal != $currValN ]] && [[ ${#autoVal} > 0 ]]; then + autoVal=$(grep "$MOTOR_PV$field " "$file" | awk '{print $2}') + if [[ $autoVal != "$currValN" ]] && [[ ${#autoVal} -gt 0 ]]; then #if $autoVal #check that this is not empty. - file_date=`echo $file | awk -F sav_ '{ print $2 }'` - if [[ $currVal != $currValN ]]; then - echo $MOTOR_PV$field current: $currValN '('$currVal')' -- $autoVal at $file_date , was same last: $same_value_dat + file_date=$(echo "$file" | awk -F sav_ '{ print $2 }') + if [[ $currVal != "$currValN" ]]; then + echo "$MOTOR_PV$field current: $currValN '('$currVal')' -- $autoVal at $file_date , was same last: $same_value_dat" else - echo $MOTOR_PV$field current: $currValN -- $autoVal at $file_date , was same last: $same_value_dat + echo "$MOTOR_PV$field current: $currValN -- $autoVal at $file_date , was same last: $same_value_dat" fi else - same_value_dat=`echo $file | awk -F sav_ '{ print $2 }'` + same_value_dat=$(echo "$file" | awk -F sav_ '{ print $2 }') fi done echo done -elif [ $2 == 'archive' ]; then +elif [[ $2 == 'archive' ]]; then echo 'Command-line archiver is not implemented yet' elif [[ "$2" == *pmgr* ]]; then - HUTCH=`echo $MOTOR_PV | cut -d : -f 1` + HUTCH=$(echo "$MOTOR_PV" | cut -d : -f 1) hutch=${HUTCH,,} - ACTION=`echo $2 | cut -d _ -f 2` + ACTION=$(echo "$2" | cut -d _ -f 2) if [[ $ACTION == 'diff' ]]; then - /reg/g/pcds/config/$hutch/pmgr/pmgrUtils.sh $ACTION $MOTOR_PV + /reg/g/pcds/config/"$hutch"/pmgr/pmgrUtils.sh "$ACTION" "$MOTOR_PV" elif [[ $ACTION == 'save' ]]; then - echo 'Differences of '$MOTOR_PV' to saved config:' - /reg/g/pcds/config/$hutch/pmgr/pmgrUtils.sh diff $MOTOR_PV - echo 'Save current config (yes/no)? '; read ANSWER + echo "Differences of $MOTOR_PV to saved config:" + /reg/g/pcds/config/"$hutch"/pmgr/pmgrUtils.sh diff "$MOTOR_PV" + echo 'Save current config (yes/no)? '; read -r ANSWER if [[ $ANSWER == 'yes' ]]; then echo 'Save now...' - /reg/g/pcds/config/$hutch/pmgr/pmgrUtils.sh save $MOTOR_PV + /reg/g/pcds/config/"$hutch"/pmgr/pmgrUtils.sh save "$MOTOR_PV" echo 'Saved.' fi else - echo $ACTION ' is not yet implemented for the pmgr function of motorInfo' + echo "$ACTION is not yet implemented for the pmgr function of motorInfo" fi else - MOTOR2_PV=`echo $2 | cut -d . -f 1` + MOTOR2_PV=$(echo "$2" | cut -d . -f 1) ADD_MOTOR_PV=$MOTOR2_PV - echo 'MOTORS DIFF' $# $ADD_MOTOR_PV + echo "MOTORS DIFF $# $ADD_MOTOR_PV" while [[ $# -gt 2 ]]; do shift - ADD_MOTOR_PV=$ADD_MOTOR_PV' '`echo $2 | cut -d . -f 1` + ADD_MOTOR_PV="$ADD_MOTOR_PV $(echo "$2" | cut -d . -f 1)" done - echo Field : $MOTOR_PV -- $ADD_MOTOR_PV + echo Field : "$MOTOR_PV" -- "$ADD_MOTOR_PV" for field in $PVFIELDS; do if [[ "$field" == *RBV* ]] || [[ "$field" == *VAL* ]]; then continue fi - value_mot1=`caget -t $MOTOR_PV$field` + value_mot1=$(caget -t "$MOTOR_PV$field") values='' HAS_DIFF=0 for PV in $ADD_MOTOR_PV; do - newval=`caget -t $PV$field` + newval=$(caget -t "$PV$field") values=$values' - '$newval - if [[ $value_mot1 != $newval ]]; then + if [[ $value_mot1 != "$newval" ]]; then HAS_DIFF=1 fi done - if [[ $HAS_DIFF > 0 ]]; then - echo $field : $value_mot1 -- $values + if [[ $HAS_DIFF -gt 0 ]]; then + echo "$field" : "$value_mot1" -- "$values" fi done fi diff --git a/scripts/new_bare_repo b/scripts/new_bare_repo index d5932540..0dee128a 100755 --- a/scripts/new_bare_repo +++ b/scripts/new_bare_repo @@ -43,7 +43,7 @@ elif [[ ${CWD} != *${REPO}* ]]; then else git init cp -u /cds/sw/tools/bin/eco_tools/gitignore.template .gitignore - git add *.cfg Makefile .gitignore + git add -- *.cfg Makefile .gitignore git commit -m "Initial commit" git-bare-repo /afs/slac.stanford.edu/g/cd/swe/git/repos/package/epics/ioc/"${HUTCH}"/"${REPO}".git git remote add origin /afs/slac.stanford.edu/g/cd/swe/git/repos/package/epics/ioc/"${HUTCH}"/"${REPO}".git diff --git a/scripts/pcds_conda b/scripts/pcds_conda index 7ad47665..1e794176 100755 --- a/scripts/pcds_conda +++ b/scripts/pcds_conda @@ -136,4 +136,3 @@ if [ -n "${SSH_CONNECTION}" ]; then fi fi fi - diff --git a/scripts/pkg_release b/scripts/pkg_release index 570a774f..16a72ed8 100755 --- a/scripts/pkg_release +++ b/scripts/pkg_release @@ -42,12 +42,12 @@ if ! ping -c 1 github.com &> /dev/null; then fi echo "Connection successful." TEST_OUTPUT=$(ssh -Tx git@github.com 2>&1) # Test ssh key with github and use ssh if appropriate, https otherwise -if echo $TEST_OUTPUT | grep "successfully authenticated" > /dev/null; then +if echo "$TEST_OUTPUT" | grep "successfully authenticated" > /dev/null; then echo "Attemping clone using SSH..." echo "URL = $SSH_URL" set -e # Catch error in git clone git clone "${SSH_URL}" "${TEMP}" -elif echo $TEST_OUTPUT | grep "Permission denied\|no kex alg" > /dev/null; then +elif echo "$TEST_OUTPUT" | grep "Permission denied\|no kex alg" > /dev/null; then echo "Attemping clone using HTTPS..." echo "URL = $URL" set -e # Catch error in git clone @@ -61,7 +61,7 @@ echo "Checking out tag..." pushd "${TEMP}" git tag -l | grep "${TAG}" >/dev/null if [ "${?}" == "1" ]; then - echo "Error: could not find tag "${TAG}". Aborting." + echo "Error: could not find tag \"${TAG}.\" Aborting." echo "Available tags:" git tag -l exit @@ -69,8 +69,8 @@ fi set -e # Catch error in git checkout git checkout "${TAG}" popd -echo "Renaming "${TEMP}" directory to ${TAG}" +echo "Renaming \"${TEMP}\" directory to ${TAG}" mv "${TEMP}" "${TAG}" echo "Write-protecting directory..." chmod -R a-w "${TAG}" -echo "Created $(readlink -f ${TAG})" +echo "Created $(readlink -f "$TAG")" diff --git a/scripts/pmgr b/scripts/pmgr index 1c4949e0..e368c67d 100755 --- a/scripts/pmgr +++ b/scripts/pmgr @@ -18,6 +18,6 @@ if [[ -n $1 && ! $1 =~ '--' ]]; then HUTCH=$1 shift else - HUTCH=`get_hutch_name` + HUTCH=$(get_hutch_name) fi -/reg/g/pcds/pyps/config/${HUTCH}/pmgr/pmgr --type ims_motor --hutch ${HUTCH} $@ & +/reg/g/pcds/pyps/config/"$HUTCH"/pmgr/pmgr --type ims_motor --hutch "$HUTCH" "$@" & diff --git a/scripts/pydev_register b/scripts/pydev_register index 7d039d66..7aefe230 100755 --- a/scripts/pydev_register +++ b/scripts/pydev_register @@ -24,7 +24,7 @@ elif [ ! -e "${1}" ]; then fi PYDEV_DIR=~/pydev -full_path="$(readlink -f $1)" +full_path=$(readlink -f "$1") if [ "${2}" == "module" ]; then link="${PYDEV_DIR}" elif [ "${2}" == "bin" ]; then diff --git a/scripts/restartdaq b/scripts/restartdaq index 1530e9c8..eadd59d1 100755 --- a/scripts/restartdaq +++ b/scripts/restartdaq @@ -41,13 +41,13 @@ do s) SILENT=1 ;; - m) + m) AIMHOST=$OPTARG ;; - c) - CORESIZE=2000000000 + c) + CORESIZE=2000000000 ;; - d) + d) DSSTEST=1 ;; ?) @@ -88,6 +88,7 @@ cd /reg/g/pcds/dist/pds/"$HUTCH"/scripts/ || exit DAQNETWORK='fez' LCLS2_HUTCHES="rix, tmo, ued" if echo "$LCLS2_HUTCHES" | grep -iw "$HUTCH" > /dev/null; then + # shellcheck source=/reg/g/pcds/dist/pds/rix/scripts/setup_env.sh source /reg/g/pcds/dist/pds/"$HUTCH"/scripts/setup_env.sh PROCMGR='procmgr' DAQNETWORK='drp' @@ -101,8 +102,7 @@ if [ "$IS_DAQ_HOST" == 0 ]; then WORKINGHOSTS='' #make sure at least cds is up. for HOST in $HOSTS; do - ping -w 2 "$HOST" >/dev/null 2>&1 - if [[ $? == 0 ]]; then + if ping -w 2 "$HOST" >/dev/null 2>&1; then WORKINGHOSTS=$WORKINGHOSTS' '$HOST fi done @@ -117,12 +117,12 @@ else DAQHOST=$(wheredaq) fi -PLATFORM=$(grep 'if not platform' /reg/g/pcds/dist/pds/"$HUTCH"/scripts/$CNFFILE | awk '{print $NF}' | sed s/\'//g) +PLATFORM=$(grep 'if not platform' /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNFFILE" | awk '{print $NF}' | sed s/\'//g) if [[ "$DAQHOST" != *$NOTRUNNING* ]]; then echo stop the DAQ on "$DAQHOST" from "$HOSTNAME" T="$(date +%s%N)" $PROCMGR stop \ - /reg/g/pcds/dist/pds/"$HUTCH"/scripts/$CNFFILE + /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNFFILE" if [ -f /reg/g/pcds/dist/pds/"$HUTCH"/scripts/p"$PLATFORM"$CNFEXT.running ]; then @@ -138,7 +138,7 @@ else echo while DAQ reports to not run, will stop the DAQ on "$DAQHOST" from "$HOSTNAME" to clear the p"$PLATFORM"$CNFEXT.running file T="$(date +%s%N)" $PROCMGR stop \ - /reg/g/pcds/dist/pds/"$HUTCH"/scripts/$CNFFILE + /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNFFILE" if [ -f /reg/g/pcds/dist/pds/"$HUTCH"/scripts/p"$PLATFORM"$CNFEXT.running ]; then echo 'the DAQ did not stop properly, exit now and try again follow the escalation procedure' @@ -156,7 +156,7 @@ T="$(date +%s%N)" echo start DAQ on "$AIMHOST" if [ "$HOSTNAME" == "$AIMHOST" ]; then $PROCMGR start \ - /reg/g/pcds/dist/pds/"$HUTCH"/scripts/$CNFFILE -c $CORESIZE -o /reg/g/pcds/pds/"$HUTCH"/logfiles + /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNFFILE" -c $CORESIZE -o /reg/g/pcds/pds/"$HUTCH"/logfiles else ssh -Y "$AIMHOST" restartdaq fi @@ -191,7 +191,7 @@ if [ ${#DOWIN} != 0 ] || [ ${#SELPART} != 0 ]; then SELPART=0 fi fi - if [ -f /reg/neh/operator/"$HUTCH"\opr/bin/"$HUTCH"\_cleanup_windows_daq ]; then + if [ -f /reg/neh/operator/"$HUTCH"opr/bin/"$HUTCH"_cleanup_windows_daq ]; then if [ ${#DOWIN} != 0 ]; then echo 'This instrument does not have standard locations for DAQ windows setup' fi @@ -199,7 +199,7 @@ if [ ${#DOWIN} != 0 ] || [ ${#SELPART} != 0 ]; then fi fi -if [ ${#DOWIN} != 0 ]; then +if [ ${#DOWIN} != 0 ]; then T="$(date +%s%N)" if [ "$HUTCH" == 'xpp' ]; then test=$(xdotool search --sync --onlyvisible --name 'ProcStat') @@ -208,25 +208,25 @@ if [ ${#DOWIN} != 0 ]; then sleep 2 fi echo 'resorting the windows now using: /reg/neh/operator/'"$HUTCH"'opr/bin/'"$HUTCH"'_cleanup_windows_daq' - /reg/neh/operator/"$HUTCH"\opr/bin/"$HUTCH"\_cleanup_windows_daq + /reg/neh/operator/"$HUTCH"opr/bin/"$HUTCH"_cleanup_windows_daq Tdinter="$(($(date +%s%N)-T))" Sinter="$((Tdinter/1000000000))" Minter="$((Tdinter/1000000))" echo 'and '"$Sinter"'.'"$Minter"' extra seconds for windows' fi -if [ ${#SELPART} != 0 ]; then +if [ ${#SELPART} != 0 ]; then DAQC=$(xdotool search --onlyvisible --name 'DAQ Control') #echo $DAQC xdotool mousemove --sync --window "$DAQC" 80 230 xdotool windowfocus "$DAQC" - xdotool click 1 - + xdotool click 1 + PARTSEL=$(xdotool search --onlyvisible --sync --name 'Partition Selection') YLOW=$(xdotool search --name 'Partition Selection' getwindowgeometry %@ | grep Geometry | awk '{print $2}' | sed s/x/" "/g | awk '{print $2}') #echo $PARTSEL - xdotool mousemove --sync --window "$PARTSEL" 80 $(("$YLOW"-28)) - xdotool click 1 + xdotool mousemove --sync --window "$PARTSEL" 80 $(("$YLOW"-28)) + xdotool click 1 fi if [ "$SILENT" == 0 ];then diff --git a/scripts/serverStat b/scripts/serverStat index abdd856e..99cc581f 100755 --- a/scripts/serverStat +++ b/scripts/serverStat @@ -6,11 +6,11 @@ names_from_name(){ fi INNAME=$1 if [[ $INNAME == *'-ipmi'* ]]; then - INNAME=$(echo "$INNAME" | sed s/-ipmi//g) + INNAME=${INNAME//-ipmi/} elif [[ $INNAME == *'-fez'* ]]; then - INNAME=$(echo "$INNAME" | sed s/-fez//g) + INNAME=${INNAME//-fez/} elif [[ $INNAME == *'-ana'* ]]; then - INNAME=$(echo "$INNAME" | sed s/-ana//g) + INNAME=${INNAME//-ana/} fi CDSNAME=$INNAME CDSIP=$(netconfig search "$CDSNAME" | grep IP: | awk '{print $2}') @@ -79,7 +79,7 @@ done HOST_HAS_FEZ=$(netconfig search "$HOSTNAME"-fez --brief | wc -l) -let HOST_HAS_FEZ-=1 +(( HOST_HAS_FEZ-=1 )) if [[ $# -lt 2 ]]; then if [[ $# -lt 1 ]]; then @@ -118,18 +118,18 @@ fi if [[ $NAME == *'-ipmi'* ]]; then NAMEIPMI=$NAME - NAME=$(echo "$NAME" | sed s/-ipmi//g) + NAME=${NAME//-ipmi/} DEV=$NAME elif [[ $NAME == *'-fez'* ]]; then - NAME=$(echo "$NAME" | sed s/-fez//g) + NAME=${NAME//-fez/} DEV=$NAME elif [[ $NAME == *'-ana'* ]]; then - NAME=$(echo "$NAME" | sed s/-ana//g) + NAME=${NAME//-ana/} fi if [[ $NAME == *rec* ]]; then if [[ $CMD == "off" ]] || [[ $CMD == "cycle" ]]; then - echo "This is a recorder, better not to power cycle unless necessary, try to reset first. Quit? " "$NAME" "$CMD"; read ANSWER + echo "This is a recorder, better not to power cycle unless necessary, try to reset first. Quit? " "$NAME" "$CMD"; read -r ANSWER if [[ $ANSWER == 'y' ]] || [[ $ANSWER == 'Y' ]] || [[ $ANSWER == 'yes' ]]; then printf 'quit now\n' exit 0 @@ -147,22 +147,22 @@ if [[ $ISSRV -lt 1 ]] && [[ $HUTCH != 'unknown_hutch' ]]; then if [[ $DEV =~ 'event' ]]; then DSSNODES=$(grep dss_nodes "$CNF" | grep -v '^#' | head -n1 | grep -oE "daq-$HUTCH-dss[[:digit:]]+") - NEVENT=$(echo "${DEV:5}") # grab the index (e.g. 2 if $DEV is event2) - SEDNUM=$(($NEVENT+1)) # adjust the number to correctly index the list of dssnodes with sed + NEVENT=${DEV:5} # grab the index (e.g. 2 if $DEV is event2) + SEDNUM=$((NEVENT + 1)) # adjust the number to correctly index the list of dssnodes with sed NAME=$(echo "$DSSNODES" | sed -n ${SEDNUM}p) if [[ -z $NAME ]]; then echo "dss node not found for $DEV, exiting..." >&2 exit 1 fi else - NDEV=$(grep "$DEV" "$CNF" | grep -v '#' | grep host | wc -l) + NDEV=$(grep "$DEV" "$CNF" | grep -v '#' | grep -c host) if [ "$NDEV" -eq 1 ]; then - NAME=$(grep "$DEV" "$CNF" | grep -v '#' | grep host | awk '{print $1}' | sed s/{host://g | sed s/,// | sed s/_/-/g | sed s/\'//g | sed s/-fez//g) + NAME=$(grep "$DEV" "$CNF" | grep -v '#' | grep host | awk '{print $1}' | sed s/"{host:"//g | sed s/,// | sed s/_/-/g | sed s/\'//g | sed s/-fez//g) elif [ "$NDEV" -eq 0 ]; then echo 'No device of this name found, exiting...' >&2 exit 1 else - NAME=$(grep "$DEV'" "$CNF" | grep -v '#' | grep host | awk '{print $1}' | sed s/{host://g | sed s/,// | sed s/_/-/g) + NAME=$(grep "$DEV'" "$CNF" | grep -v '#' | grep host | awk '{print $1}' | sed s/"{host:"//g | sed s/,// | sed s/_/-/g) fi fi if [[ $NAME ]]; then @@ -204,22 +204,19 @@ elif [[ $CMD == "expert" ]]; then echo -e "" echo -e "Checking host/ipmi/fez network interfaces are online:" echo -e "-------------------------------------------------" - ping -w 2 "$NAME" >/dev/null 2>&1 - if [[ $? == 0 ]]; then + if ping -w 2 "$NAME" >/dev/null 2>&1; then echo "$NAME pings." CDS_ONLINE=1 else echo "$NAME does not ping." CDS_ONLINE=0 fi - ping -w 2 "$NAME"-ipmi >/dev/null 2>&1 - if [[ $? == 0 ]]; then + if ping -w 2 "$NAME"-ipmi >/dev/null 2>&1; then echo "$NAME-ipmi pings." else echo "$NAME-ipmi does not ping." fi - ping -w 2 "$NAME"-fez >/dev/null 2>&1 - if [[ $? == 0 ]]; then + if ping -w 2 "$NAME"-fez >/dev/null 2>&1; then echo "$NAME-fez pings." else echo "$NAME-fez does not ping." @@ -287,7 +284,7 @@ elif [[ $CMD == "status" ]]; then if [[ $HOST_HAS_FEZ -ge 1 ]]; then PNGFEZ=$(ping -c 1 "$FEZNAME" | grep transmitted | awk '{print $4}') echo "$NAME is a server with IP: $CDSIP (ping success: $PNG), $FEZIP (ping success: $PNGFEZ)" - if [[ $(($PNG+$PNGFEZ)) -gt 1 ]]; then + if [[ $((PNG + PNGFEZ)) -gt 1 ]]; then echo 'cds&fez interfaces are up' fi else diff --git a/scripts/set_gem_timing b/scripts/set_gem_timing index feb8d59d..d3533b67 100755 --- a/scripts/set_gem_timing +++ b/scripts/set_gem_timing @@ -50,7 +50,7 @@ else fi SET_IOC_PATH_CMD="${IMGR_CMD_PATH} ioc-lfe-gasdet-daq --upgrade $IOC_PATH" -CURR_IOC_PATH=$(${IMGR_CMD_PATH} ioc-lfe-gasdet-daq --info | awk 'FNR == 4 {print $3}') #Warning: make sure your release of imgr supports --info +CURR_IOC_PATH=$(${IMGR_CMD_PATH} ioc-lfe-gasdet-daq --info | awk 'FNR == 4 {print $3}') #Warning: make sure your release of imgr supports --info if [[ $CURR_IOC_PATH = "$IOC_PATH" ]]; then echo "Current IOC path is: $CURR_IOC_PATH which is equiavlent to requested IOC path for the requested switch to $1, not invoking imgr" else @@ -58,4 +58,4 @@ else $SET_IOC_PATH_CMD fi -exit 0 \ No newline at end of file +exit 0 diff --git a/scripts/startami b/scripts/startami index 7e906a65..7c3106b2 100755 --- a/scripts/startami +++ b/scripts/startami @@ -33,15 +33,15 @@ do ;; esac done -shift "$(($OPTIND-1))" +shift "$((OPTIND-1))" -if [[ `whoami` != *'opr'* ]]; then +if [[ $(whoami) != *'opr'* ]]; then echo "Please run ami from the operator account!" exit fi -HUTCH=`get_hutch_name` -EXPNAME=`get_curr_exp` +HUTCH=$(get_hutch_name) +EXPNAME=$(get_curr_exp) CNFEXT=.cnf if [[ $HUTCH == 'cxi' ]]; then @@ -61,46 +61,46 @@ if [[ -z $CONFIG ]]; then fi # -# this is XPP specific. Don't think we should have local plugins anyways, -# only release ones. +# this is XPP specific. Don't think we should have local plugins anyways, +# only release ones. # source /reg/g/pcds/setup/pathmunge.sh -if [ $HUTCH == 'xpp' ]; then +if [[ $HUTCH == 'xpp' ]]; then ldpathmunge /reg/neh/operator/xppopr/ami_plugins -elif [ $HUTCH == 'xcs' ]; then +elif [[ $HUTCH == 'xcs' ]]; then ldpathmunge /reg/neh/operator/xcsopr/online/ami_plugins fi -DAQHOST=`wheredaq` -ami_base_path=`grep ami_base_path /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG | grep -v '#' | grep -v 'ami_base_path+' | awk 'BEGIN { FS = "=" }; { print $2}' | sed s/\'//g` -ami_path=$ami_base_path`grep ami_path /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG | grep -v 'ami_path+' | grep -v '#' | awk 'BEGIN { FS = "= " }; { print $2}' | sed s/ami_base_path+// | sed s/\'//g` +DAQHOST=$(wheredaq) +ami_base_path=$(grep ami_base_path /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" | grep -v '#' | grep -v 'ami_base_path+' | awk 'BEGIN { FS = "=" }; { print $2}' | sed s/\'//g) +ami_path=$ami_base_path$(grep ami_path /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" | grep -v 'ami_path+' | grep -v '#' | awk 'BEGIN { FS = "= " }; { print $2}' | sed s/ami_base_path+// | sed s/\'//g) -proxy_cds=`/reg/g/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr status /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG | grep ami_proxy | awk {'print $1'} | sed s/'-fez'/''/g` +proxy_cds=$(/reg/g/pcds/dist/pds/"$HUTCH"/current/tools/procmgr/procmgr status /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" | grep ami_proxy | awk '{print $1}' | sed s/'-fez'/''/g) -amicmd=`grep ami_client /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG | grep -v '#' | awk 'BEGIN { FS = ":" }; { print $4}' | sed s/ami_path//g | sed s/\'+proxy_cds/$proxy_cds/g | sed s:\'+expname:$EXPNAME/:g | sed s/+\'//g | sed s/\'\}\)//g` +amicmd=$(grep ami_client /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" | grep -v '#' | awk 'BEGIN { FS = ":" }; { print $4}' | sed s/ami_path//g | sed s/\'+proxy_cds/"$proxy_cds"/g | sed s:\'+expname:"$EXPNAME"/:g | sed s/+\'//g | sed s/\'\}\)//g) if [[ "$DAQHOST" == *"$HOSTNAME" ]]; then # Check host and daq host line share host name... #running on the DAQ host, this will restart the ami_client! - read -p "Do you really intend to restart the ami_client on $DAQHOST? (y/n)" + read -rp "Do you really intend to restart the ami_client on $DAQHOST? (y/n)" if [ "$REPLY" == "y" ];then echo "Restarting the ami_client..."; - /reg/g/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr stop \ - /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG ami_client - /reg/g/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr start \ - /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG -c 2000000000 -o /reg/g/pcds/pds/$HUTCH/logfiles ami_client + /reg/g/pcds/dist/pds/"$HUTCH"/current/tools/procmgr/procmgr stop \ + /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" ami_client + /reg/g/pcds/dist/pds/"$HUTCH"/current/tools/procmgr/procmgr start \ + /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" -c 2000000000 -o /reg/g/pcds/pds/"$HUTCH"/logfiles ami_client exit else - read -p "Do you want to start a second client on the DAQ host $DAQHOST? (y/n)" + read -rp "Do you want to start a second client on the DAQ host $DAQHOST? (y/n)" if [ "$REPLY" == "n" ];then exit else - echo "Starting another ami_client on "$DAQHOST , calling: + echo "Starting another ami_client on $DAQHOST , calling:" fi fi else - echo --- connect to proxy on: $proxy_cds, calling: -fi + echo --- "connect to proxy on: $proxy_cds, calling:" +fi -echo $ami_path$amicmd -exec $ami_path$amicmd& +echo "$ami_path$amicmd" +exec "$ami_path$amicmd&" diff --git a/scripts/stopami b/scripts/stopami index 8a25d193..7931ce85 100755 --- a/scripts/stopami +++ b/scripts/stopami @@ -13,37 +13,37 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then exit 0 fi -HUTCH=`get_hutch_name` -DAQHOST=`wheredaq` -RESCNT=`echo $DAQHOST |wc| awk {'print $2'}` -if [ $RESCNT -eq 1 ]; then - if [ $HOSTNAME == $DAQHOST ]; then +HUTCH=$(get_hutch_name) +DAQHOST=$(wheredaq) +RESCNT=$(echo "$DAQHOST" |wc| awk '{print $2}') +if [[ $RESCNT -eq 1 ]]; then + if [[ $HOSTNAME == "$DAQHOST" ]]; then #running on the DAQ host, this will restart the ami_client! - read -p "Do you really intend to stop the ami_client on $DAQHOST where the daq is running? (y/n)" + read -rp "Do you really intend to stop the ami_client on $DAQHOST where the daq is running? (y/n)" if [ "$REPLY" == "y" ];then echo "Restarting the ami_client..."; - /reg/g/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr stop \ - /reg/g/pcds/dist/pds/$HUTCH/scripts/$HUTCH.cnf ami_client + /reg/g/pcds/dist/pds/"$HUTCH"/current/tools/procmgr/procmgr stop \ + /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$HUTCH".cnf ami_client fi fi fi -AMI_PROCID=`ps -ef | grep online_ami | grep current | awk {'print $2'}` -HAVE_ID=`echo $AMI_PROCID | wc | awk {'print $2'}` -if [ $HAVE_ID -gt 0 ]; then +AMI_PROCID=$(pgrep online_ami) +HAVE_ID=$(echo "$AMI_PROCID" | wc | awk '{print $2}') +if [[ $HAVE_ID -gt 0 ]]; then for id in $AMI_PROCID; do - echo 'killing ' $id - kill $id + echo "killing $id" + kill "$id" done fi sleep 2 -AMI_PROCID=`ps -ef | grep online_ami | grep current | awk {'print $2'}` -HAVE_ID=`echo $AMI_PROCID | wc | awk {'print $2'}` -if [ $HAVE_ID -gt 0 ]; then +AMI_PROCID=$(pgrep online_ami) +HAVE_ID=$(echo "$AMI_PROCID" | wc | awk '{print $2}') +if [[ $HAVE_ID -gt 0 ]]; then for id in $AMI_PROCID; do - echo 'kill -9 ' $id - kill -9 $id + echo "kill -9 $id" + kill -9 "$id" done fi diff --git a/scripts/stopdaq b/scripts/stopdaq index a9b59e91..69c3cd13 100755 --- a/scripts/stopdaq +++ b/scripts/stopdaq @@ -33,12 +33,13 @@ fi unset PYTHONPATH unset LD_LIBRARY_PATH -#go to hutches DAQ scripts directory +#go to hutches DAQ scripts directory #(puts pid file in consistent location - necessary for stopping for LCLS-II DAQ) cd /reg/g/pcds/dist/pds/"$HUTCH"/scripts/ || exit LCLS2_HUTCHES="rix, tmo, ued" if echo "$LCLS2_HUTCHES" | grep -iw "$HUTCH" > /dev/null; then + # shellcheck source=/reg/g/pcds/dist/pds/rix/scripts/setup_env.sh source /reg/g/pcds/dist/pds/"$HUTCH"/scripts/setup_env.sh PROCMGR='procmgr' else @@ -49,7 +50,7 @@ PLATFORM=$(grep 'if not platform' /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNFFIL if [[ "$DAQHOST" != 'DAQ is not running' ]]; then T="$(date +%s%N)" echo stop the DAQ from "$HOSTNAME" - $PROCMGR stop /reg/g/pcds/dist/pds/"$HUTCH"/scripts/$CNFFILE + $PROCMGR stop /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNFFILE" if [ -f /reg/g/pcds/dist/pds/"$HUTCH"/scripts/p"$PLATFORM""$CNFEXT".running ]; then echo 'the DAQ did not stop properly, exit now and try again or call your POC or the DAQ phone' exit diff --git a/scripts/takepeds b/scripts/takepeds index 5502fdb1..6622d3cb 100755 --- a/scripts/takepeds +++ b/scripts/takepeds @@ -10,7 +10,7 @@ Takes a run with dark images for use in pedestals, and posts to the elog. EOF } -if [[($1 == "--help") || ($1 == "-h")]]; then +if [[ ($1 == "--help") || ($1 == "-h")]]; then usage exit 0 fi @@ -19,16 +19,16 @@ DAQ_RELEASE=/cds/group/pcds/dist/pds/current # -R: for norecord , -r forces recording station=$(get_info --getstation) -$DAQ_RELEASE/tools/scanning/take_pedestals -p $station -r +$DAQ_RELEASE/tools/scanning/take_pedestals -p "$station" -r elogMessage="DARK" source pcds_conda PYCMD=LogBookPost -EXP=`get_curr_exp` -RUN=`get_lastRun` +EXP=$(get_curr_exp) +RUN=$(get_lastRun) HUTCH=${EXP:0:3} -echo $PYCMD -i "${HUTCH^^}" -u `whoami` -e "$EXP" -t DARK -r $RUN -m "$elogMessage" -$PYCMD -i "${HUTCH^^}" -u `whoami` -p pcds -e "$EXP" -t DARK -r $RUN -m "$elogMessage"& +echo $PYCMD -i "${HUTCH^^}" -u "$(whoami)" -e "$EXP" -t DARK -r "$RUN" -m "$elogMessage" +$PYCMD -i "${HUTCH^^}" -u "$(whoami)" -p pcds -e "$EXP" -t DARK -r "$RUN" -m "$elogMessage"& -echo 'Please call: makepeds -q milano -r '`get_lastRun`' -u ' +echo "Please call: makepeds -q milano -r $(get_lastRun) -u " diff --git a/scripts/verify-hutch b/scripts/verify-hutch index 62c93e12..71cb065b 100755 --- a/scripts/verify-hutch +++ b/scripts/verify-hutch @@ -4,7 +4,7 @@ usage(){ cat << EOF usage: ${BASH_SOURCE[0]} -Verifies that the passed argument is a known hutch, exit 0 for success and exit 1 for failure. +Verifies that the passed argument is a known hutch, exit 0 for success and exit 1 for failure. EOF } @@ -21,7 +21,7 @@ fi hutch=${1,,} for i in "tmo" "txi" "rix" "xpp" "xcs" "mfx" "cxi" "mec" "ued" "ued" "det" "lfe" "kfe" "tst" "las" "hpl"; do - if [[ $hutch == $i ]]; then + if [[ $hutch == "$i" ]]; then exit 0 fi done diff --git a/scripts/wheredaq b/scripts/wheredaq index e760304e..f93b697c 100755 --- a/scripts/wheredaq +++ b/scripts/wheredaq @@ -38,6 +38,6 @@ if [[ ! -f /reg/g/pcds/dist/pds/"$HUTCH"/scripts/p"$PLATFORM".cnf.running ]]; th echo 'DAQ is not running in '"$HUTCH" fi else - DAQ_HOST=$(grep "'HOST'" /reg/g/pcds/dist/pds/"$HUTCH"/scripts/p"$PLATFORM".cnf.running | awk {'print $3'} | sed s/\'//g) + DAQ_HOST=$(grep "'HOST'" /reg/g/pcds/dist/pds/"$HUTCH"/scripts/p"$PLATFORM".cnf.running | awk '{print $3}' | sed s/\'//g) echo 'DAQ is running on '"$DAQ_HOST" fi diff --git a/scripts/wherepsana b/scripts/wherepsana index 6c1a8323..1d9a41a1 100755 --- a/scripts/wherepsana +++ b/scripts/wherepsana @@ -20,14 +20,14 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then exit 0 fi -HUTCH=`get_info --gethutch` +HUTCH=$(get_info --gethutch) for i in "xpp" "xcs" "mfx" "cxi" "mec" "det"; do - if [ $HUTCH == $i ]; then + if [[ $HUTCH == "$i" ]]; then FOUNDHUTCH=1 break fi done -if [ -z $FOUNDHUTCH ]; then +if [[ -z $FOUNDHUTCH ]]; then echo 'could not determine hutch or hutch not implemented, quit' exit fi @@ -48,7 +48,7 @@ do ;; esac done -shift "$(($OPTIND-1))" +shift "$((OPTIND-1))" # If specified a config file, then use that if [[ -z $CONFIG ]]; then @@ -63,40 +63,39 @@ if [[ -z $CONFIG ]]; then elif [[ -z $CONFIG ]]; then echo 'You must provide cxi config file (-c) if not on daq machine' exit 1 - fi + fi fi CONFIG=$HUTCH$CNFEXT fi #create a tempoprary file with the procStatus so we only call that once; -/reg/g/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr status /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG > /tmp/procServStatus.$$ - -PSANA_NODES=(`grep monreqsrvpsana /tmp/procServStatus.$$ | awk {'print $1'}`) +/reg/g/pcds/dist/pds/"$HUTCH"/current/tools/procmgr/procmgr status /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" > /tmp/procServStatus.$$ +mapfile -t PSANA_NODES < <(grep monreqsrvpsana /tmp/procServStatus.$$ | awk '{print $1}') if [[ -z $DETAIL ]]; then NODESTR='' - for ((idx=0; idx<${#PSANA_NODES[@]}; ++idx)); do - NODESTR=$NODESTR${PSANA_NODES[idx]}','; + for ((idx=0; idx<${#PSANA_NODES[@]}; ++idx)); do + NODESTR=$NODESTR${PSANA_NODES[idx]}','; done - echo ${NODESTR::-1} + echo "${NODESTR::-1}" else - EVENT=(`grep event /tmp/procServStatus.$$ | awk {'print $1'}`) - PSANA_MASKS=(`grep monreqsrvpsana /tmp/procServStatus.$$ | awk -F "-i " {'print $2'} | awk {'print $1'}`) - EVENT_MASKS=(`grep event /tmp/procServStatus.$$ | awk -F "-s " '{print $2;}' | awk '{print lshift(1,$1);}'`) + mapfile -t EVENT < <(grep event /tmp/procServStatus.$$ | awk '{print $1}') + mapfile -t PSANA_MASKS < <(grep monreqsrvpsana /tmp/procServStatus.$$ | awk -F "-i " '{print $2}' | awk '{print $1}') + mapfile -t EVENT_MASKS < <(grep event /tmp/procServStatus.$$ | awk -F "-s " '{print $2;}' | awk '{print lshift(1,$1);}') echo 'psana runs on the following nodes looking at event nodes '${#EVENT[@]} NODESTR='' - for ((idx=0; idx<${#PSANA_NODES[@]}; ++idx)); do - echo -n ${PSANA_NODES[idx]}':' + for ((idx=0; idx<${#PSANA_NODES[@]}; ++idx)); do + echo -n "${PSANA_NODES[idx]}:" MASKS=${PSANA_MASKS[idx]} - for ((m=0; m<${#EVENT[@]}; ++m)); do - if [ $((${MASKS}&${EVENT_MASKS[m]})) != 0 ]; then - echo -n ' '${EVENT[m]} - MASKS=$((${MASKS}&~${EVENT_MASKS[m]})) + for ((m=0; m<${#EVENT[@]}; ++m)); do + if [ $((MASKS&EVENT_MASKS[m])) != 0 ]; then + echo -n "${EVENT[m]}" + MASKS=$((MASKS&~EVENT_MASKS[m])) fi done - if [ ${MASKS} != '0' ]; then - echo " MISSING MON MASK: "$MASKS + if [[ ${MASKS} != '0' ]]; then + echo "MISSING MON MASK: $MASKS" fi echo "" done diff --git a/scripts/xpp_update_happi_line b/scripts/xpp_update_happi_line index 8f2f884e..bc9c098b 100755 --- a/scripts/xpp_update_happi_line +++ b/scripts/xpp_update_happi_line @@ -1,4 +1,4 @@ #!/bin/bash source pcds_conda -cd $ENG_TOOL_SCRIPTS +cd "$ENG_TOOL_SCRIPTS" python xpp_update_happi_line.py "$@" From 273ecd5c608b20f4f373968274ebb37fa230d1fa Mon Sep 17 00:00:00 2001 From: Kaushik Malapati Date: Mon, 6 May 2024 15:02:52 -0700 Subject: [PATCH 2/3] Tentatively adding shellfmt to precommit --- .pre-commit-config.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e8582abb..a947b2cb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,3 +32,8 @@ repos: rev: 5.11.5 hooks: - id: isort +- repo: https://github.com/pecigonzalo/pre-commit-shfmt + rev: v2.2.0 + hooks: + - id: shell-fmt-go + args: [-l, -d, -s, -fn, -sr, -ci, -i=4] From 6a5b3290330dfc45435dd0f6f1f39a05bb26f621 Mon Sep 17 00:00:00 2001 From: KaushikMalapati <80156796+KaushikMalapati@users.noreply.github.com> Date: Mon, 13 May 2024 15:39:42 -0500 Subject: [PATCH 3/3] Update scripts/takepeds Co-authored-by: Zachary Lentz --- scripts/takepeds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/takepeds b/scripts/takepeds index 6622d3cb..b3eff728 100755 --- a/scripts/takepeds +++ b/scripts/takepeds @@ -10,7 +10,7 @@ Takes a run with dark images for use in pedestals, and posts to the elog. EOF } -if [[ ($1 == "--help") || ($1 == "-h")]]; then +if [[ ($1 == "--help") || ($1 == "-h") ]]; then usage exit 0 fi