/[pdpsoft]/trunk/nl.biggrid.dans/job-info
ViewVC logotype

Contents of /trunk/nl.biggrid.dans/job-info

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2582 - (show annotations) (download)
Tue Nov 20 12:07:59 2012 UTC (9 years, 8 months ago) by svn
File size: 7054 byte(s)
First released version
1 #!/bin/bash
2
3 if [ ! "x$0" = "x${0#-}" ]
4 then
5 echo "Don't source me, just run!" 1>&2
6 return
7 fi
8 . ${0%/*}/libdans.sh
9
10 # Load global defaults (vars: vo, ARCHIVE, LFC_*, SRM_*)
11 loadDefaults $0
12
13 DEBUG=0
14 QUIET=0
15 KEEPGOING=0
16 JOBID=0
17 START_INDEX=1
18 END_INDEX=0
19 USAGE="\
20 $0 - print info on all DANS '${ARCHIVE}' jobs in ${JOBDIR}
21 Usage: ./job-info [-q|--quiet] [-d|--debug] [-k|--keepgoing] [--archive=archive]
22 [--jobdir=dir] [--id=N] [--start=N] [--end=N]
23 Where:
24 --keepgoing tells $0 to keep going after an error
25 --archive=archive specifies the name of the archive (default='${ARCHIVE}')
26 --jobdir=dir specifies the directory where the DANS jobs are stored
27 (default='${JOBDIR}')
28 --id=N specifies the DANS job id
29 --start=N specifies the starting DANS job id (default=1)
30 --end=N specifies the end DANS job id (default=ALL)
31 "
32
33 # Parse commandline parameters
34 while [ $# -gt 0 ]
35 do
36 case "$1" in
37 (-h|--help) echo "${USAGE}"
38 exit 0
39 ;;
40 (-d|--debug) let DEBUG+=1
41 ;;
42 (-q|--quiet) QUIET=1
43 ;;
44 (-k|--keepgoing|--keep-going)
45 KEEPGOING=1
46 ;;
47 (--archive) ARCHIVE=$2
48 shift
49 ;;
50 (--archive=*) ARCHIVE=${1##--archive=}
51 ;;
52 (--jobdir|--job-dir)
53 JOBDIR=$2
54 shift
55 ;;
56 (--jobdir=*) JOBDIR=${1##--jobdir=}
57 ;;
58 (--job-dir=*) JOBDIR=${1##--job-dir=}
59 ;;
60 (--id) JOBID=$2
61 shift
62 ;;
63 (--id=*) JOBID=${1##--id=}
64 ;;
65 (--start) START_INDEX=$2
66 shift
67 ;;
68 (--start=*) START_INDEX=${1##--start=}
69 ;;
70 (--end) END_INDEX=$2
71 shift
72 ;;
73 (--end=*) END_INDEX=${1##--end=}
74 ;;
75 (-*) echo "Invalid option: $1"
76 exit 1
77 ;;
78 esac
79 shift
80 done
81
82 # not needed
83 # checkProxy "${vo}"
84
85 # Check that the jobdir actually exists
86 if [ ! -d "${JOBDIR}/." ]
87 then
88 abort 1 "Job directory '${JOBDIR}' does not exist!"
89 fi
90
91 # sanitize start and end indices
92 lastdansjobid=`(cd "${JOBDIR}"; ls -1dr [0-9][0-9][0-9][0-9][0-9] 2> /dev/null| head -1)`
93 if [ ${START_INDEX} -lt 1 -o ${START_INDEX} -gt ${lastdansjobid} ]
94 then
95 abort 2 "Invalid start job index specified!"
96 fi
97 if [ ${END_INDEX} -lt 1 -o ${END_INDEX} -gt ${lastdansjobid} ]
98 then
99 if [ ${END_INDEX} -ne 0 ]
100 then
101 warn "Invalid end job index specified, adjusting to ${lastdansjobid}"
102 fi
103 END_INDEX=${lastdansjobid}
104 fi
105 if [ ${JOBID} -gt 0 ]
106 then
107 if [ ${JOBID} -le ${lastdansjobid} ]
108 then
109 START_INDEX=${JOBID}
110 END_INDEX=${JOBID}
111 else
112 abort 3 "Invalid DANS jobid '${JOBID}' specified!"
113 fi
114 fi
115
116 # now check all known jobs
117 numjobs=0
118 for jobid in `seq ${START_INDEX} ${END_INDEX}`
119 do
120 jobdir=`printf "${JOBDIR}/%05d" ${jobid}`
121
122 if [ -r "${jobdir}/jobid" ]
123 then
124 cd "${jobdir}"
125
126 info "DANS-job ${jobdir##*/} found"
127 # check for job files
128 files_found=`ls -d jdl job*log output 2> /dev/null`
129 debug " Job files found: " $files_found
130
131 if [ -r jdl ]
132 then
133 let numjobs++
134 # Extract the executable (script) and arguments from the jdl
135 executable=`sed -n 's/^Executable = "\(.*\)".*/\1/p' jdl`
136 arguments=`sed -n 's/^Arguments = "\(.*\)".*/\1/p' jdl`
137
138 case "${executable}" in
139 (check-archive.sh) jobtype="Check Archive job "
140 ;;
141 (compress-archive.sh) jobtype="Compress Archive job (tar->tar.gz)"
142 ;;
143 (*) jobtype="Unknown"
144 ;;
145 esac
146
147 # The arguments should look something like 'Crome X Y'
148 jobarchive=`echo $arguments | awk '{ print $1 }'`
149 start_index=`echo $arguments | awk '{ print $2 }'`
150 end_index=`echo $arguments | awk '{ print $3 }'`
151 info " $jobtype Archive=\"$jobarchive\" Start_index=$start_index End_index=$end_index"
152 else
153 warn "No jdl file found in ${jobdir}, skipping"
154 fi
155 # check for status file(s)
156 statusfile=`(ls -1tr Status=* 2> /dev/null)`
157 debug "Status files: " $statusfile
158
159 if [ `echo "${statusfile}" | wc -l` -gt 1 ]
160 then
161 warn "Multiple status files found! Using most recent one."
162 fi
163
164 status=${statusfile##*Status=}
165 case "${status}" in
166 (Submitted) status_line=" Status: Job submitted, waiting for scheduler"
167 ;;
168 (Scheduled) status_line=" Status: Job scheduled, waiting for start"
169 ;;
170 (Running|Really-running)
171 status_line=" Status: Job running"
172 ;;
173 (Done) status_line=" Status: Job finished, output pending"
174 ;;
175 (Cleared) status_line=" Status: Job done, output retrieved "
176 ;;
177 (Aborted) status_line=" Status: Job aborted!"
178 ;;
179 (Cancelled) status_line=" Status: Job cancelled by user!"
180 ;;
181 (*) status_line=" Status: unknown! : \"${statusfile}\""
182 ;;
183 esac
184
185 exitcode=-1
186 timestamp=
187 if [ "x${status}" = "xCleared" ]
188 then
189 if [ -r job-logging-info.log ]
190 then
191 job_log=`awk 'BEGIN { done=0 };
192 /^Event: Done/{ done=1 };
193 /^- Exit code/{ have_exitcode=1 ; exitcode=$5 };
194 /^- Timestamp/{ timestamp=$4 " " $5 " " $6 " " $7 " "$8 " " $9 };
195 /^- Source/{ if ($4 != "LogMonitor" ) done=0 ;
196 if ( done && have_exitcode)
197 {
198 printf "exitcode=\"%s\" ; timestamp=\"%s\"\n", exitcode, timestamp }
199 }' job-logging-info.log`
200 debug "Job logging info: $job_log"
201 eval `echo "$job_log"`
202 status_line="${status_line} Exit code=$exitcode Timestamp=$timestamp"
203 else
204 warn "No job-logging-info.log file found in ${jobdir}, skipping"
205 fi
206 fi
207 info "${status_line}"
208 fi
209 done
210
211 if [ ${numjobs} -eq 0 ]
212 then
213 info "No jobs found!"
214 elif [ ${numjobs} -gt 1 ]
215 then
216 info "Found ${numjobs} DANS jobs"
217 fi
218

Properties

Name Value
svn:executable

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28