Skip to content
Snippets Groups Projects
Commit 905b6ebf authored by Mark Olesen's avatar Mark Olesen
Browse files

wmakeScheduler: prefix non-coloured output with hostname; cosmetic changes

parent 911c4616
Branches
Tags
No related merge requests found
...@@ -57,14 +57,15 @@ lockDir=$HOME/.wmakeScheduler ...@@ -57,14 +57,15 @@ lockDir=$HOME/.wmakeScheduler
# count the total number of slots available and exit # count the total number of slots available and exit
if [ "$1" = "-count" ] if [ "$1" = "-count" ]
then then
expr $( expr $(
for slotGroup in $WM_HOSTS for slotGroup in $WM_HOSTS
do do
n=${slotGroup##*:} n=${slotGroup##*:}
if [ "$n" = "${slotGroup%%:*}" ]; then n=1; fi # missing ':' [ "$n" = "${slotGroup%%:*}" ] && n=1 # missing ':'
echo "+ ${n:-1}" echo "+ ${n:-1}"
done) done
exit 0 )
exit 0
fi fi
# where to source WM_PROJECT settings in a remote shell # where to source WM_PROJECT settings in a remote shell
...@@ -75,25 +76,26 @@ fi ...@@ -75,25 +76,26 @@ fi
sourceFoam=false # fallback command sourceFoam=false # fallback command
case $SHELL in case $SHELL in
*/csh | */tcsh ) # [t]csh vs bash|ksh|sh */csh | */tcsh ) # [t]csh vs bash|ksh|sh
shellRc=cshrc shellRc=cshrc
;; ;;
*) *)
shellRc=bashrc shellRc=bashrc
;; ;;
esac esac
# check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/ # check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/
# check ~/.$WM_PROJECT/ # check ~/.$WM_PROJECT/
# check <installedProject>/etc/ # check <installedProject>/etc/
if [ "$WM_PROJECT" ]; then if [ "$WM_PROJECT" ]
then
for i in \ for i in \
$HOME/.$WM_PROJECT/$WM_PROJECT_VERSION \ $HOME/.$WM_PROJECT/$WM_PROJECT_VERSION \
$HOME/.$WM_PROJECT \ $HOME/.$WM_PROJECT \
$WM_PROJECT_DIR/etc \ $WM_PROJECT_DIR/etc \
; ;
do do
if [ -f "$i/$shellRc" ]; then if [ -f "$i/$shellRc" ]
then
sourceFoam="$i/$shellRc" sourceFoam="$i/$shellRc"
break break
fi fi
...@@ -105,7 +107,8 @@ fi ...@@ -105,7 +107,8 @@ fi
# attempt to preserve the installation directory 'FOAM_INST_DIR' # attempt to preserve the installation directory 'FOAM_INST_DIR'
case $sourceFoam in case $sourceFoam in
*/bashrc) */bashrc)
if [ "$FOAM_INST_DIR" ]; then if [ "$FOAM_INST_DIR" ]
then
sourceFoam='[ "$WM_PROJECT" ] || '"FOAM_INST_DIR=$FOAM_INST_DIR . $sourceFoam" sourceFoam='[ "$WM_PROJECT" ] || '"FOAM_INST_DIR=$FOAM_INST_DIR . $sourceFoam"
else else
sourceFoam='[ "$WM_PROJECT" ] || '". $sourceFoam" sourceFoam='[ "$WM_PROJECT" ] || '". $sourceFoam"
...@@ -125,25 +128,50 @@ rcmd=$(echo $* | sed -e s/\"/\'\"\'/g) ...@@ -125,25 +128,50 @@ rcmd=$(echo $* | sed -e s/\"/\'\"\'/g)
# Convert WM_COLOURS into an array # Convert WM_COLOURS into an array
declare colours declare colourList
nColours=0 nColours=0
for col in $WM_COLOURS for col in $WM_COLOURS
do do
colours[$nColours]=$col colourList[$nColours]=$col
((nColours = $nColours + 1)) ((nColours = $nColours + 1))
done done
# Bashism: make pipe fail early. This make sure return value of compilation # Bashism: make pipe fail early.
# is returned and not of colouring pipe. # This ensures the return value of the command is returned and not of the
# colouring pipe etc.
set -o pipefail set -o pipefail
# Define function to colour output by argument 1
colourPipe(){ #
if [ "$1" ]; then # colour output by argument 1
(while read line; do setterm -foreground $1; echo "$line" ; done; setterm -foreground default) #
else colourPipe()
cat {
fi if [ "$1" ]
then
(
while read line
do
setterm -foreground $1
echo "$line"
done
setterm -foreground default
)
else
cat
fi
}
#
# prefix message with [HOSTNAME]
#
prefixPipe()
{
while read line
do
echo "[$@] $line"
done
} }
...@@ -151,61 +179,60 @@ colourIndex=0 ...@@ -151,61 +179,60 @@ colourIndex=0
while : while :
do do
for slotGroup in $WM_HOSTS for slotGroup in $WM_HOSTS
do do
# split 'host:N', but catch 'host:' and 'host' too # split 'host:N', but catch 'host:' and 'host' too
host=${slotGroup%%:*} host=${slotGroup%%:*}
n=${slotGroup##*:} n=${slotGroup##*:}
if [ "$n" = "$host" ]; then n=1; fi # missing ':' [ "$n" = "$host" ] && n=1 # missing ':'
: ${n:=1} : ${n:=1}
i=0 i=0
while [ "$i" -lt "$n" ] while [ "$i" -lt "$n" ]
do do
lockFile="$lockDir/$host:$i" lockFile="$lockDir/$host:$i"
if lockfile -r0 "$lockFile" 2>/dev/null; then if lockfile -r0 "$lockFile" 2>/dev/null
if [ "$WM_COLOURS" ]; then then
# Set colour if [ "$nColours" -gt 0 ]
colour="${colours[$colourIndex]}" then
# Set colour and index to next colour
if [ "$host" = "$HOST" ]; then colour="${colourList[$colourIndex]}"
eval $* 2>&1 | colourPipe "$colour" colourIndex=$(expr $colourIndex + 1)
elif [ -n "$JOB_ID" ]; then [ "$colourIndex" -lt "$nColours" ] || colourIndex=0
qrsh -inherit -v PWD $host "$rcmd"
else if [ "$host" = "$HOST" ]; then
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | colourPipe "$colour" eval $* 2>&1 | colourPipe "$colour"
fi elif [ -n "$JOB_ID" ]; then
retval=$? qrsh -inherit -v PWD $host "$rcmd"
else else
if [ "$host" = "$HOST" ]; then ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | colourPipe "$colour"
eval $* fi
elif [ -n "$JOB_ID" ]; then retval=$?
qrsh -inherit -v PWD $host "$rcmd" else
else if [ "$host" = "$HOST" ]; then
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" eval $* 2>&1 | prefixPipe "$host"
fi elif [ -n "$JOB_ID" ]; then
retval=$? qrsh -inherit -v PWD $host "$rcmd" | prefixPipe "$host"
fi else
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | prefixPipe "$host"
# Release lock fi
rm -f "$lockFile" 2>/dev/null retval=$?
exit $retval
fi fi
i=$(expr $i + 1)
# Cycle through colours # Release lock
colourIndex=$(expr $colourIndex + 1) rm -f "$lockFile" 2>/dev/null
if (( $colourIndex >= $nColours )); then exit $retval
colourIndex=0 fi
fi i=$(expr $i + 1)
done done
done done
# Did not find any free slots. Rest a bit. # Did not find any free slots. Rest a bit.
sleep 1 sleep 1
done done
if [ "$WM_COLOURS" ]; then if [ "$nColours" -gt 0 ]
setterm -foreground default then
setterm -foreground default
fi fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment