2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
8 #-------------------------------------------------------------------------------
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
29 # Uses finishedJobs/ and runningJobs/ and stateFile to print job info
31 #------------------------------------------------------------------------------
34 JOBSTRING
='%4s %8s %20s %10s %8s %4s %12s %12s %20s\n'
35 DEFSTATEFILE
=$HOME/.OpenFOAM
/foamCheckJobs.out
38 #-------------------------------------------------------------------------------
42 #-------------------------------------------------------------------------------
46 Usage: $Script [stateFile]
48 This program prints a table of all running and finished jobs.
50 It is normally used in conjunction with foamCheckJobs which outputs
51 a "stateFile" containing the actual process status of all jobs.
53 If stateFile is not supplied, the default is used:
60 # printJob stat user case machine pid ncpus start end code
62 printf "$JOBSTRING" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
66 # getRawEntry dictionary entry
67 # Prints value of dictionary entry
69 grep -v '^//' $1 |
grep "^[ \t]*$2 " |
sed -e "s/^[ \t]*$2 [ ]*//"
72 # getEntry dictionary entry
73 # Like getRawEntry but strips " and ending ';'
75 getRawEntry
$1 $2 |
sed -e 's/^"//' -e 's/;$//' -e 's/"$//'
80 # Returns 0 if directory contains files/directories
90 # rightStr nChars string
91 # Prints rightmost nChars of string
93 echo "$2" |
sed -e "s/.*\(.\{$1\}\)\$/\1/"
97 echo "$2" |
sed -e "s/\(.\{$1\}\).*/\1/"
100 #-------------------------------------------------------------------------------
104 #-------------------------------------------------------------------------------
108 if [ "$1" = "-h" -o "$1" = "-help" ]
116 STATEFILE
=${STATEFILE:-$DEFSTATEFILE}
121 #- Check a few things
123 if [ ! "$FOAM_JOB_DIR" ]
125 echo "$Script : FOAM_JOB_DIR environment variable not set."
129 if [ ! -d "$FOAM_JOB_DIR" ]
131 echo "$Script : directory does not exist."
132 echo " FOAM_JOB_DIR=$FOAM_JOB_DIR"
136 if [ ! -d "$FOAM_JOB_DIR/runningJobs" -o ! -d "$FOAM_JOB_DIR/finishedJobs" ]
138 echo "$Script : invalid directory."
139 echo " FOAM_JOB_DIR=$FOAM_JOB_DIR"
145 if [ -f "$STATEFILE" ]
148 echo "Using process information from"
151 echo " $FOAM_JOB_DIR"
155 echo "Cannot read $STATEFILE."
162 printJob
'stat' 'user' 'case' 'machine' 'pid' 'ncpu' 'start' 'end' 'code'
163 printJob
'----' '----' '----' '-------' '---' '----' '-----' '---' '----'
172 if notEmpty
$FOAM_JOB_DIR/runningJobs
174 for f
in `ls -t $FOAM_JOB_DIR/runningJobs/*`
176 machinePid
=`basename $f`
178 machine
=`echo $machinePid | sed -e 's/\..*$//'`
179 machine
=`rightStr 10 "$machine"`
181 pid
=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
185 stat
=`getEntry $STATEFILE $machinePid`
189 case=`getEntry $f 'case'`
191 case=`echo $case | sed -e 's!/.*!!'` # strip processorXXX ending
192 case=`rightStr 20 "$case"`
194 start
=`getEntry $f 'startDate'`
195 start
=${start:-'---'}
196 start
=`leftStr 12 "$start"`
200 code
=`getEntry $f 'code'`
203 code
=`basename $code`
207 code
=`rightStr 20 "$code"`
209 nProcs
=`getEntry $f 'nProcs'`
210 nProcs
=${nProcs:-'1'}
215 nProcs
=`rightStr 3 "$nProcs"`
217 user
=`getEntry $f 'username'`
219 user
=`leftStr 8 "$user"`
221 printJob
"$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
229 if notEmpty
$FOAM_JOB_DIR/finishedJobs
231 for f
in `ls -t $FOAM_JOB_DIR/finishedJobs/*`
233 machinePid
=`basename $f`
235 machine
=`echo $machinePid | sed -e 's/\..*$//'`
236 machine
=`rightStr 10 "$machine"`
238 pid
=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
240 end
=`getEntry $f endDate`
242 end
=`leftStr 12 "$end"`
246 stat
=`getEntry $STATEFILE $machinePid`
250 case=`getEntry $f case`
251 case=`echo $case | sed -e 's!/.*!!'` # strip processorXXX ending
253 case=`rightStr 20 "$case"`
255 start
=`getEntry $f startDate`
256 start
=${start:-'---'}
257 start
=`leftStr 12 "$start"`
259 code
=`getEntry $f code`
262 code
=`basename $code`
266 code
=`rightStr 20 "$code"`
268 nProcs
=`getEntry $f 'nProcs'`
269 nProcs
=${nProcs:-'1'}
274 nProcs
=`rightStr 3 "$nProcs"`
276 user
=`getEntry $f 'username'`
278 user
=`leftStr 8 "$user"`
280 printJob
"$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
284 #------------------------------------------------------------------------------