2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 the
14 # Free Software Foundation; either version 2 of the License, or (at your
15 # 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, write to the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 # Uses finishedJobs/ and runningJobs/ and stateFile to print job info
32 #------------------------------------------------------------------------------
34 PROGNAME
=`basename $0`
35 TMPFILE
=/tmp
/${PROGNAME}$$.tmp
36 TMPFILE2
=/tmp
/${PROGNAME}$$.tmp2
37 JOBSTRING
='%4s %8s %20s %10s %8s %4s %12s %12s %20s\n'
38 DEFSTATEFILE
=$HOME/.OpenFOAM
/foamCheckJobs.out
41 #-------------------------------------------------------------------------------
45 #-------------------------------------------------------------------------------
49 Usage: $PROGNAME [stateFile]
51 This program prints a table of all the running and finished jobs.
53 It is normally used in conjunction with foamCheckJobs which outputs
54 a "stateFile" containing the actual process status of all jobs.
56 If stateFile is not supplied the default $DEFSTATEFILE
62 # printJob stat user case machine pid ncpus start end code
64 printf "$JOBSTRING" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
68 # getRawEntry dictionary entry
69 # Prints value of dictionary entry
71 grep -v '^//' $1 |
grep "^[ \t]*$2 " |
sed -e "s/^[ \t]*$2 [ ]*//"
74 # getEntry dictionary entry
75 # Like getRawEntry but strips " and ending ';'
77 getRawEntry
$1 $2 |
sed -e 's/^"//' -e 's/;$//' -e 's/"$//'
82 # Returns 0 if directory contains files/directories
84 if [ "`ls $1`" ]; then
91 # rightStr nChars string
92 # Prints rightmost nChars of string
94 echo "$2" |
sed -e "s/.*\(.\{$1\}\)\$/\1/"
98 echo "$2" |
sed -e "s/\(.\{$1\}\).*/\1/"
101 #-------------------------------------------------------------------------------
105 #-------------------------------------------------------------------------------
107 if [ ! "$FOAM_JOB_DIR" ]; then
108 echo "$PROGNAME : FOAM_JOB_DIR environment variable not set."
112 if [ ! -d "$FOAM_JOB_DIR" ]; then
113 echo "$PROGNAME : directory does not exist."
114 echo " FOAM_JOB_DIR: $FOAM_JOB_DIR"
116 if [ ! -d "$FOAM_JOB_DIR/runningJobs" -o ! -d "$FOAM_JOB_DIR/finishedJobs" ]; then
117 echo "$PROGNAME : invalid directory."
118 echo " FOAM_JOB_DIR: $FOAM_JOB_DIR"
122 if [ $# -eq 1 ]; then
123 if [ "$1" = '-h' ]; then
129 elif [ $# -eq 0 ]; then
130 STATEFILE
=${STATEFILE:-$DEFSTATEFILE}
137 if [ -f "$STATEFILE" ]; then
139 echo "Using process information from"
142 echo " $FOAM_JOB_DIR"
146 echo "Cannot read $STATEFILE."
153 printJob
'stat' 'user' 'case' 'machine' 'pid' 'ncpu' 'start' 'end' 'code'
154 printJob
'----' '----' '----' '-------' '---' '----' '-----' '---' '----'
163 if notEmpty
$FOAM_JOB_DIR/runningJobs
; then
164 for f
in `ls -t $FOAM_JOB_DIR/runningJobs/*`
166 machinePid
=`basename $f`
168 machine
=`echo $machinePid | sed -e 's/\..*$//'`
169 machine
=`rightStr 10 "$machine"`
171 pid
=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
173 if [ "$STATEFILE" ]; then
174 stat
=`getEntry $STATEFILE $machinePid`
178 case=`getEntry $f 'case'`
180 case=`echo $case | sed -e 's!/.*!!'` #strip of processorXXX ending
181 case=`rightStr 20 "$case"`
183 start
=`getEntry $f 'startDate'`
184 start
=${start:-'---'}
185 start
=`leftStr 12 "$start"`
189 code
=`getEntry $f 'code'`
191 code
=`basename $code`
195 code
=`rightStr 20 "$code"`
197 nProcs
=`getEntry $f 'nProcs'`
198 nProcs
=${nProcs:-'1'}
199 if [ $nProcs -eq 1 ]; then
202 nProcs
=`rightStr 3 "$nProcs"`
204 user
=`getEntry $f 'username'`
206 user
=`leftStr 8 "$user"`
208 printJob
"$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
216 if notEmpty
$FOAM_JOB_DIR/finishedJobs
; then
217 for f
in `ls -t $FOAM_JOB_DIR/finishedJobs/*`
219 machinePid
=`basename $f`
221 machine
=`echo $machinePid | sed -e 's/\..*$//'`
222 machine
=`rightStr 10 "$machine"`
224 pid
=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
226 end
=`getEntry $f endDate`
228 end
=`leftStr 12 "$end"`
230 if [ "$STATEFILE" ]; then
231 stat
=`getEntry $STATEFILE $machinePid`
235 case=`getEntry $f case`
236 case=`echo $case | sed -e 's!/.*!!'` #strip of processorXXX ending
238 case=`rightStr 20 "$case"`
240 start
=`getEntry $f startDate`
241 start
=${start:-'---'}
242 start
=`leftStr 12 "$start"`
244 code
=`getEntry $f code`
246 code
=`basename $code`
250 code
=`rightStr 20 "$code"`
252 nProcs
=`getEntry $f 'nProcs'`
253 nProcs
=${nProcs:-'1'}
254 if [ $nProcs -eq 1 ]; then
257 nProcs
=`rightStr 3 "$nProcs"`
259 user
=`getEntry $f 'username'`
261 user
=`leftStr 8 "$user"`
263 printJob
"$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
267 #------------------------------------------------------------------------------