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

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

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: 6659 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 - check the status of all DANS '${ARCHIVE}' jobs in ${JOBDIR}
21 Usage: ./job-status [-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 checkProxy "${vo}"
83
84 # Check that the jobdir actually exists
85 if [ ! -d "${JOBDIR}/." ]
86 then
87 abort 1 "Job directory '${JOBDIR}' does not exist!"
88 fi
89
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 debug "DANS-job ${jobdir##*/} found"
125 # check for the *latest* status file
126 statusfile=`(cd "$jobdir"; ls -1t Status=* 2> /dev/null | head -1)`
127 debug " Status files: " $statusfile
128 do_update=1
129 status="${statusfile#Status=}"
130 case "${status}" in
131 (Done) debug " Job finished"
132 do_update=0
133 ;;
134 (Cleared) debug " Job output retrieved and cleared"
135 do_update=0
136 ;;
137 (Aborted) debug " Job aborted!"
138 do_update=0
139 ;;
140 (Cancelled) debug " Job cancelled!"
141 do_update=0
142 ;;
143 esac
144
145 if [ ${do_update} -eq 1 ]
146 then
147 let numjobs++
148 debug " Updating job status"
149 jobid=`cat "${jobdir}/jobid"`
150 job_status=`glite-wms-job-status "${jobid}" 2> /dev/null`
151 if [ $? -eq 0 ]
152 then
153 new_status=`echo "${job_status}" | sed -n 's/^Current Status: *\([A-Za-z]*\) .*/\1/p'`
154 if [ "x${new_status}" = "xDone" ]
155 then
156 exit_code=`echo "${job_status}" | sed -n 's/^Exit code: *\([0-9]*\).*/\1/p'`
157 printf "%s %-60s Status=%s (Exit code=%d)\n" ${jobdir##*/} $jobid ${new_status} ${exit_code}
158
159 # Retrieve the output for Done jobs
160 echo " Retrieving job output into ${jobdir}/output"
161
162 glite-wms-job-output --noint --dir "${jobdir}/output" --logfile ${jobdir}/job-get-output.log "$jobid" > /dev/null 2>&1
163 if [ $? -eq 0 ]
164 then
165 job_output="`whoami`_${jobid##*/}"
166 # move output to the right place
167 mv -f "${jobdir}/output/${job_output}"/* "${jobdir}/output"
168 rmdir "${jobdir}/output/${job_output}"
169 else
170 warn "Could not retrieve job output!"
171 fi
172 else
173 printf "%s %-60s Status=%s\n" ${jobdir##*/} $jobid ${new_status}
174 fi
175
176 if [ "x${new_status}" = "xDone" -o "x${new_status}" = "xAborted" -o "x${new_status}" = "xCancelled" ]
177 then
178 # get the full job logging info
179 glite-wms-job-logging-info -v 3 "${jobid}" > ${jobdir}/job-logging-info.log 2>&1
180 if [ $? -ne 0 ]
181 then
182 warn "Could not retrieve job logging info!"
183 fi
184 fi
185
186 rm -f ${jobdir}/Status=*
187 touch ${jobdir}/Status=${new_status}
188 else
189 warn "Error retrieving job info for ${jobid}, skipping"
190 fi
191 fi
192 else
193 debug "No jobid file found in ${jobdir}, skipping"
194 fi
195 done
196
197 if [ ${numjobs} -eq 0 ]
198 then
199 info "No jobs found!"
200 elif [ ${numjobs} -gt 1 ]
201 then
202 info "Found ${numjobs} DANS jobs"
203 fi
204

Properties

Name Value
svn:executable

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