ENH: Updated FreeFOAM ascii-art in template-files
[freefoam.git] / bin / foamPrintJobs.in
blobe3ca0ee0140dee594736e71b8175a212a596b43d
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/.FreeFOAM/foamCheckJobs.out
41 #-------------------------------------------------------------------------------
43 # Functions
45 #-------------------------------------------------------------------------------
47 . @FF_DATA_DIR@/shellFunctions/jobControlFunctions
49 printUsage() {
50 cat << LABEL
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
59 is used.
60 LABEL
64 # printJob stat user case machine pid ncpus start end code
65 printJob() {
66 printf "$JOBSTRING" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
69 # rightStr nChars string
70 # Prints rightmost nChars of string
71 rightStr() {
72 echo "$2" | sed -e "s/.*\(.\{$1\}\)\$/\1/"
75 leftStr() {
76 echo "$2" | sed -e "s/\(.\{$1\}\).*/\1/"
79 #-------------------------------------------------------------------------------
81 # Main
83 #-------------------------------------------------------------------------------
85 FOAM_JOB_DIR=`foamJobDir`
87 if [ ! "$FOAM_JOB_DIR" ]; then
88 echo "$PROGNAME : FOAM_JOB_DIR environment variable not set."
89 exit 1
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
104 printUsage
105 exit 1
106 else
107 STATEFILE=$1
109 elif [ $# -eq 0 ]; then
110 STATEFILE=${STATEFILE:-$DEFSTATEFILE}
111 else
112 printUsage
113 exit 1
117 if [ -f "$STATEFILE" ]; then
118 echo ""
119 echo "Using process information from"
120 echo " $STATEFILE"
121 echo "on jobs in"
122 echo " $FOAM_JOB_DIR"
123 echo ""
124 else
125 echo ""
126 echo "Cannot read $STATEFILE."
127 echo ""
128 STATEFILE=''
132 #-- print header
133 printJob 'stat' 'user' 'case' 'machine' 'pid' 'ncpu' 'start' 'end' 'code'
134 printJob '----' '----' '----' '-------' '---' '----' '-----' '---' '----'
138 #-- print submitted
141 #-- print running
142 echo "Running:"
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`
156 stat=${stat:-'UNKN'}
158 case=`getEntry $f 'case'`
159 case=${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"`
167 end='---'
169 code=`getEntry $f 'code'`
170 if [ "$code" ]; then
171 code=`basename $code`
172 else
173 code='---'
175 code=`rightStr 20 "$code"`
177 nProcs=`getEntry $f 'nProcs'`
178 nProcs=${nProcs:-'1'}
179 if [ $nProcs -eq 1 ]; then
180 nProcs='---'
182 nProcs=`rightStr 3 "$nProcs"`
184 user=`getEntry $f 'username'`
185 user=${user:-'---'}
186 user=`leftStr 8 "$user"`
188 printJob "$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
189 done
193 #-- print finished
194 echo ""
195 echo "Finished:"
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`
207 end=${end:-'---'}
208 end=`leftStr 12 "$end"`
210 if [ "$STATEFILE" ]; then
211 stat=`getEntry $STATEFILE $machinePid`
213 stat=${stat:-'UNKN'}
215 case=`getEntry $f case`
216 case=`echo $case | sed -e 's!/.*!!'` #strip of processorXXX ending
217 case=${case:-'---'}
218 case=`rightStr 20 "$case"`
220 start=`getEntry $f startDate`
221 start=${start:-'---'}
222 start=`leftStr 12 "$start"`
224 code=`getEntry $f code`
225 if [ "$code" ]; then
226 code=`basename $code`
227 else
228 code='---'
230 code=`rightStr 20 "$code"`
232 nProcs=`getEntry $f 'nProcs'`
233 nProcs=${nProcs:-'1'}
234 if [ $nProcs -eq 1 ]; then
235 nProcs='---'
237 nProcs=`rightStr 3 "$nProcs"`
239 user=`getEntry $f 'username'`
240 user=${user:-'---'}
241 user=`leftStr 8 "$user"`
243 printJob "$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
244 done
247 #------------------------------------------------------------------------------