2 #---------------------------------*- sh -*-------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 1991-2010 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
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 #------------------------------------------------------------------------------
33 PROGNAME
=`basename $0`
34 TMPFILE
=/tmp
/${PROGNAME}$$.tmp
35 TMPFILE2
=/tmp
/${PROGNAME}$$.tmp2
36 JOBSTRING
='%4s %8s %20s %10s %8s %4s %12s %12s %20s\n'
37 DEFSTATEFILE
=$HOME/.OpenFOAM
/foamCheckJobs.out
40 #-------------------------------------------------------------------------------
44 #-------------------------------------------------------------------------------
48 Usage: $PROGNAME [stateFile]
50 This program prints a table of all the running and finished jobs.
52 It is normally used in conjunction with foamCheckJobs which outputs
53 a "stateFile" containing the actual process status of all jobs.
55 If stateFile is not supplied the default $DEFSTATEFILE
61 # printJob stat user case machine pid ncpus start end code
63 printf "$JOBSTRING" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
67 # getRawEntry dictionary entry
68 # Prints value of dictionary entry
70 grep -v '^//' $1 |
grep "^[ \t]*$2 " |
sed -e "s/^[ \t]*$2 [ ]*//"
73 # getEntry dictionary entry
74 # Like getRawEntry but strips " and ending ';'
76 getRawEntry
$1 $2 |
sed -e 's/^"//' -e 's/;$//' -e 's/"$//'
81 # Returns 0 if directory contains files/directories
83 if [ "`ls $1`" ]; then
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 #-------------------------------------------------------------------------------
106 if [ ! "$FOAM_JOB_DIR" ]; then
107 echo "$PROGNAME : FOAM_JOB_DIR environment variable not set."
111 if [ ! -d "$FOAM_JOB_DIR" ]; then
112 echo "$PROGNAME : directory does not exist."
113 echo " FOAM_JOB_DIR: $FOAM_JOB_DIR"
115 if [ ! -d "$FOAM_JOB_DIR/runningJobs" -o ! -d "$FOAM_JOB_DIR/finishedJobs" ]; then
116 echo "$PROGNAME : invalid directory."
117 echo " FOAM_JOB_DIR: $FOAM_JOB_DIR"
121 if [ $# -eq 1 ]; then
122 if [ "$1" = '-h' ]; then
128 elif [ $# -eq 0 ]; then
129 STATEFILE
=${STATEFILE:-$DEFSTATEFILE}
136 if [ -f "$STATEFILE" ]; then
138 echo "Using process information from"
141 echo " $FOAM_JOB_DIR"
145 echo "Cannot read $STATEFILE."
152 printJob
'stat' 'user' 'case' 'machine' 'pid' 'ncpu' 'start' 'end' 'code'
153 printJob
'----' '----' '----' '-------' '---' '----' '-----' '---' '----'
162 if notEmpty
$FOAM_JOB_DIR/runningJobs
; then
163 for f
in `ls -t $FOAM_JOB_DIR/runningJobs/*`
165 machinePid
=`basename $f`
167 machine
=`echo $machinePid | sed -e 's/\..*$//'`
168 machine
=`rightStr 10 "$machine"`
170 pid
=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
172 if [ "$STATEFILE" ]; then
173 stat
=`getEntry $STATEFILE $machinePid`
177 case=`getEntry $f 'case'`
179 case=`echo $case | sed -e 's!/.*!!'` #strip of processorXXX ending
180 case=`rightStr 20 "$case"`
182 start
=`getEntry $f 'startDate'`
183 start
=${start:-'---'}
184 start
=`leftStr 12 "$start"`
188 code
=`getEntry $f 'code'`
190 code
=`basename $code`
194 code
=`rightStr 20 "$code"`
196 nProcs
=`getEntry $f 'nProcs'`
197 nProcs
=${nProcs:-'1'}
198 if [ $nProcs -eq 1 ]; then
201 nProcs
=`rightStr 3 "$nProcs"`
203 user
=`getEntry $f 'username'`
205 user
=`leftStr 8 "$user"`
207 printJob
"$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
215 if notEmpty
$FOAM_JOB_DIR/finishedJobs
; then
216 for f
in `ls -t $FOAM_JOB_DIR/finishedJobs/*`
218 machinePid
=`basename $f`
220 machine
=`echo $machinePid | sed -e 's/\..*$//'`
221 machine
=`rightStr 10 "$machine"`
223 pid
=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
225 end
=`getEntry $f endDate`
227 end
=`leftStr 12 "$end"`
229 if [ "$STATEFILE" ]; then
230 stat
=`getEntry $STATEFILE $machinePid`
234 case=`getEntry $f case`
235 case=`echo $case | sed -e 's!/.*!!'` #strip of processorXXX ending
237 case=`rightStr 20 "$case"`
239 start
=`getEntry $f startDate`
240 start
=${start:-'---'}
241 start
=`leftStr 12 "$start"`
243 code
=`getEntry $f code`
245 code
=`basename $code`
249 code
=`rightStr 20 "$code"`
251 nProcs
=`getEntry $f 'nProcs'`
252 nProcs
=${nProcs:-'1'}
253 if [ $nProcs -eq 1 ]; then
256 nProcs
=`rightStr 3 "$nProcs"`
258 user
=`getEntry $f 'username'`
260 user
=`leftStr 8 "$user"`
262 printJob
"$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
266 #------------------------------------------------------------------------------