Upgraded the ParaView build scripts to version 3.3-cvs.
[OpenFOAM-1.5.x.git] / bin / foamPrintJobs
blobcb4b8ac25f23774bd14a1cc5ec1aba9ef356b68d
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 # \\/ M anipulation |
8 #-------------------------------------------------------------------------------
9 # License
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
20 # for more details.
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
26 # Script
27 # foamPrintJobs
29 # Description
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 #-------------------------------------------------------------------------------
43 # Functions
45 #-------------------------------------------------------------------------------
47 printUsage() {
48 cat << LABEL
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
57 is used.
58 LABEL
62 # printJob stat user case machine pid ncpus start end code
63 printJob() {
64 printf "$JOBSTRING" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
68 # getRawEntry dictionary entry
69 # Prints value of dictionary entry
70 getRawEntry() {
71 grep -v '^//' $1 | grep "^[ \t]*$2 " | sed -e "s/^[ \t]*$2 [ ]*//"
74 # getEntry dictionary entry
75 # Like getRawEntry but strips " and ending ';'
76 getEntry() {
77 getRawEntry $1 $2 | sed -e 's/^"//' -e 's/;$//' -e 's/"$//'
81 # notEmpty directory
82 # Returns 0 if directory contains files/directories
83 notEmpty() {
84 if [ "`ls $1`" ]; then
85 return 0
86 else
87 return 1
91 # rightStr nChars string
92 # Prints rightmost nChars of string
93 rightStr() {
94 echo "$2" | sed -e "s/.*\(.\{$1\}\)\$/\1/"
97 leftStr() {
98 echo "$2" | sed -e "s/\(.\{$1\}\).*/\1/"
101 #-------------------------------------------------------------------------------
103 # Main
105 #-------------------------------------------------------------------------------
107 if [ ! "$FOAM_JOB_DIR" ]; then
108 echo "$PROGNAME : FOAM_JOB_DIR environment variable not set."
109 exit 1
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
124 printUsage
125 exit 1
126 else
127 STATEFILE=$1
129 elif [ $# -eq 0 ]; then
130 STATEFILE=${STATEFILE:-$DEFSTATEFILE}
131 else
132 printUsage
133 exit 1
137 if [ -f "$STATEFILE" ]; then
138 echo ""
139 echo "Using process information from"
140 echo " $STATEFILE"
141 echo "on jobs in"
142 echo " $FOAM_JOB_DIR"
143 echo ""
144 else
145 echo ""
146 echo "Cannot read $STATEFILE."
147 echo ""
148 STATEFILE=''
152 #-- print header
153 printJob 'stat' 'user' 'case' 'machine' 'pid' 'ncpu' 'start' 'end' 'code'
154 printJob '----' '----' '----' '-------' '---' '----' '-----' '---' '----'
158 #-- print submitted
161 #-- print running
162 echo "Running:"
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`
176 stat=${stat:-'UNKN'}
178 case=`getEntry $f 'case'`
179 case=${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"`
187 end='---'
189 code=`getEntry $f 'code'`
190 if [ "$code" ]; then
191 code=`basename $code`
192 else
193 code='---'
195 code=`rightStr 20 "$code"`
197 nProcs=`getEntry $f 'nProcs'`
198 nProcs=${nProcs:-'1'}
199 if [ $nProcs -eq 1 ]; then
200 nProcs='---'
202 nProcs=`rightStr 3 "$nProcs"`
204 user=`getEntry $f 'username'`
205 user=${user:-'---'}
206 user=`leftStr 8 "$user"`
208 printJob "$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
209 done
213 #-- print finished
214 echo ""
215 echo "Finished:"
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`
227 end=${end:-'---'}
228 end=`leftStr 12 "$end"`
230 if [ "$STATEFILE" ]; then
231 stat=`getEntry $STATEFILE $machinePid`
233 stat=${stat:-'UNKN'}
235 case=`getEntry $f case`
236 case=`echo $case | sed -e 's!/.*!!'` #strip of processorXXX ending
237 case=${case:-'---'}
238 case=`rightStr 20 "$case"`
240 start=`getEntry $f startDate`
241 start=${start:-'---'}
242 start=`leftStr 12 "$start"`
244 code=`getEntry $f code`
245 if [ "$code" ]; then
246 code=`basename $code`
247 else
248 code='---'
250 code=`rightStr 20 "$code"`
252 nProcs=`getEntry $f 'nProcs'`
253 nProcs=${nProcs:-'1'}
254 if [ $nProcs -eq 1 ]; then
255 nProcs='---'
257 nProcs=`rightStr 3 "$nProcs"`
259 user=`getEntry $f 'username'`
260 user=${user:-'---'}
261 user=`leftStr 8 "$user"`
263 printJob "$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
264 done
267 #------------------------------------------------------------------------------