Last active
January 10, 2021 16:09
-
-
Save IdoBar/f3aff3d82c7245bf8157f46153eb86e6 to your computer and use it in GitHub Desktop.
A modified qstat wrapper to work with nextflow on QRIS Awoonga
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# put this file in $HOME/bin and make it executable | |
# make sure that this file is being called by default, I did this by adding `alias "qstat=~/bin/qstat"` to my ~/.bashrc | |
# Servers | |
#awoonga="@awongmgmr1.storage:16001 @awonmgr2.storage:16001" | |
#flashlite="@flm1.ipoib:16001 @flashmgr2.ipoib:16001" | |
#tinaroo="@tinmgmr1.ib0:16001 @tinmgr2.ib0:16001" | |
awoonga="@awonmgr2" | |
flashlite="@flashmgr2" | |
tinaroo="@tinmgr2" | |
opts="${*}" | |
servers="${awoonga} ${flashlite} ${tinaroo}" | |
TEMP=`getopt -o BD:EF:GHJLMQTafinqrstu:w1 --long version -n 'qstat' -- "$@"` | |
eval set -- "$TEMP" | |
# Need to find options that will allow/suppress the wide default | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-B) opt_B=1; shift ;; | |
-Q) opt_Q=1; shift ;; | |
-L) opt_L=1 ; shift ;; | |
-a) allow_w=1 ; shift ;; | |
-n) allow_w=1 ; shift ;; | |
-T) allow_w=1 ; shift ;; | |
-s) allow_w=1 ; shift ;; | |
-f) allow_w=1 ; opt_f=1; shift ;; | |
-q) deny_w=1 ; shift ;; | |
-h) deny_w=1 ; shift ;; | |
-F) deny_w=1 ; shift ;; | |
-D|-F|-u) shift 2 ;; | |
@*) servers="" ; shift ;; | |
*) shift ;; | |
esac | |
done | |
# Discover the process tree that invoked us. | |
ptree=$(/bin/ps -o'comm') | |
defs=""; wide="" | |
# If script or terminal sufficiently wide | |
if [ ${allow_w:-0} -eq 1 ] && [ ${deny_w:-0} -eq 0 ]; then | |
if ! /bin/tty -s || [ "$(/bin/tput cols)" -gt 136 ]; then wide="-w"; fi | |
fi | |
# this line makes sure that all servers are being queried when using qstat -f | |
if [ ${opt_f:-0} -eq 1 ]; then | |
/bin/timeout --foreground --kill-after=10s 10s /opt/pbs/bin/qstat ${defs} ${opts} ${wide} ${servers} | |
else | |
if [ "${opts#-L}" != "${opts}" ] || [ "${opts#-f}" != "${opts}" ]; then | |
servers="" | |
opts="${opts#-L}"; opts=${opts## } | |
if [ "${opts:-x}" != "x" ] && [ "${opts#-}" == "${opts}" ]; then opts="-${opts}"; fi | |
/opt/pbs/bin/qstat ${defs} ${opts} ${wide} ${server} | |
# Query for all servers - but timeout on no response. | |
elif [ ${opt_B:-0} -eq 1 ]; then | |
# If this is "-B" remove the "@" from servernames | |
shopt -s extglob | |
if [ "${opts##-B*( )}" != "" ]; then servers=""; fi | |
for server in ${servers//@}; do | |
/bin/timeout --foreground --kill-after=10s 10s /opt/pbs/bin/qstat ${defs} ${opts} ${server} | |
done | |
elif [ ${opts_Q:-0} -eq 1 ]; then | |
# If this is "-Q", need to add server headers | |
for server in ${servers}; do | |
sname=${server//@}; sname=${sname%:.*} | |
/bin/echo -e "\n${sname}\n" | |
/bin/timeout --foreground --kill-after=10s 10s /opt/pbs/bin/qstat -Q ${server} | |
done | |
else | |
# If script or terminal sufficiently wide | |
# Set default view | |
if [ "${opts:-x}" == "x" ]; then defs="-1n"; fi | |
for server in ${servers}; do | |
/bin/timeout --foreground --kill-after=10s 10s /opt/pbs/bin/qstat ${defs} ${opts} ${wide} ${server} | |
done | |
fi | |
fi | |
# Delay return if invoked from "watch" | |
if [ "${ptree}" != "${ptree/watch}" ]; then sleep 20; fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment