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/.FreeFOAM
/foamCheckJobs.out
41 #-------------------------------------------------------------------------------
45 #-------------------------------------------------------------------------------
47 . @FF_DATA_DIR@
/shellFunctions
/jobControlFunctions
51 Usage: $PROGNAME [stateFile]
53 This program prints a table of all the running and finished jobs.
55 It is normally used in conjunction with foamCheckJobs which outputs
56 a "stateFile" containing the actual process status of all jobs.
58 If stateFile is not supplied the default $DEFSTATEFILE
64 # printJob stat user case machine pid ncpus start end code
66 printf "$JOBSTRING" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
69 # rightStr nChars string
70 # Prints rightmost nChars of string
72 echo "$2" |
sed -e "s/.*\(.\{$1\}\)\$/\1/"
76 echo "$2" |
sed -e "s/\(.\{$1\}\).*/\1/"
79 #-------------------------------------------------------------------------------
83 #-------------------------------------------------------------------------------
85 FOAM_JOB_DIR
=`foamJobDir`
87 if [ ! "$FOAM_JOB_DIR" ]; then
88 echo "$PROGNAME : FOAM_JOB_DIR environment variable not set."
92 if [ ! -d "$FOAM_JOB_DIR" ]; then
93 echo "$PROGNAME : directory does not exist."
94 echo " FOAM_JOB_DIR: $FOAM_JOB_DIR"
96 if [ ! -d "$FOAM_JOB_DIR/runningJobs" -o ! -d "$FOAM_JOB_DIR/finishedJobs" ]; then
97 echo "$PROGNAME : invalid directory."
98 echo " FOAM_JOB_DIR: $FOAM_JOB_DIR"
102 if [ $# -eq 1 ]; then
103 if [ "$1" = '-h' ]; then
109 elif [ $# -eq 0 ]; then
110 STATEFILE
=${STATEFILE:-$DEFSTATEFILE}
117 if [ -f "$STATEFILE" ]; then
119 echo "Using process information from"
122 echo " $FOAM_JOB_DIR"
126 echo "Cannot read $STATEFILE."
133 printJob
'stat' 'user' 'case' 'machine' 'pid' 'ncpu' 'start' 'end' 'code'
134 printJob
'----' '----' '----' '-------' '---' '----' '-----' '---' '----'
143 if notEmpty
$FOAM_JOB_DIR/runningJobs
; then
144 for f
in `ls -t $FOAM_JOB_DIR/runningJobs/*`
146 machinePid
=`basename $f`
148 machine
=`echo $machinePid | sed -e 's/\..*$//'`
149 machine
=`rightStr 10 "$machine"`
151 pid
=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
153 if [ "$STATEFILE" ]; then
154 stat
=`getEntry $STATEFILE $machinePid`
158 case=`getEntry $f 'case'`
160 case=`echo $case | sed -e 's!/.*!!'` #strip of processorXXX ending
161 case=`rightStr 20 "$case"`
163 start
=`getEntry $f 'startDate'`
164 start
=${start:-'---'}
165 start
=`leftStr 12 "$start"`
169 code
=`getEntry $f 'code'`
171 code
=`basename $code`
175 code
=`rightStr 20 "$code"`
177 nProcs
=`getEntry $f 'nProcs'`
178 nProcs
=${nProcs:-'1'}
179 if [ $nProcs -eq 1 ]; then
182 nProcs
=`rightStr 3 "$nProcs"`
184 user
=`getEntry $f 'username'`
186 user
=`leftStr 8 "$user"`
188 printJob
"$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
196 if notEmpty
$FOAM_JOB_DIR/finishedJobs
; then
197 for f
in `ls -t $FOAM_JOB_DIR/finishedJobs/*`
199 machinePid
=`basename $f`
201 machine
=`echo $machinePid | sed -e 's/\..*$//'`
202 machine
=`rightStr 10 "$machine"`
204 pid
=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
206 end
=`getEntry $f endDate`
208 end
=`leftStr 12 "$end"`
210 if [ "$STATEFILE" ]; then
211 stat
=`getEntry $STATEFILE $machinePid`
215 case=`getEntry $f case`
216 case=`echo $case | sed -e 's!/.*!!'` #strip of processorXXX ending
218 case=`rightStr 20 "$case"`
220 start
=`getEntry $f startDate`
221 start
=${start:-'---'}
222 start
=`leftStr 12 "$start"`
224 code
=`getEntry $f code`
226 code
=`basename $code`
230 code
=`rightStr 20 "$code"`
232 nProcs
=`getEntry $f 'nProcs'`
233 nProcs
=${nProcs:-'1'}
234 if [ $nProcs -eq 1 ]; then
237 nProcs
=`rightStr 3 "$nProcs"`
239 user
=`getEntry $f 'username'`
241 user
=`leftStr 8 "$user"`
243 printJob
"$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
247 #------------------------------------------------------------------------------