7 |
fi |
fi |
8 |
. ${0%/*}/libdans.sh |
. ${0%/*}/libdans.sh |
9 |
|
|
10 |
# Load global defaults (vars: vo, archive, LFC_*, SRM_*) |
# Load global defaults (vars: vo, ARCHIVE, LFC_*, SRM_*) |
11 |
loadDefaults $0 |
loadDefaults $0 |
12 |
|
|
13 |
DEBUG=0 |
DEBUG=0 |
14 |
QUIET=0 |
QUIET=0 |
15 |
KEEPGOING=0 |
KEEPGOING=0 |
16 |
|
JOBID=0 |
17 |
|
START_INDEX=1 |
18 |
|
END_INDEX=0 |
19 |
USAGE="\ |
USAGE="\ |
20 |
$0 - print info on all DANS '${archive}' jobs in ${JOBDIR} |
$0 - print info on all DANS '${ARCHIVE}' jobs in ${JOBDIR} |
21 |
Usage: ./job-info [-q|--quiet] [-d|--debug] [-k|--keepgoing] [--jobdir dir] |
Usage: ./job-info [-q|--quiet] [-d|--debug] [-k|--keepgoing] [--archive=archive] |
22 |
|
[--jobdir=dir] [--id=N] [--start=N] [--end=N] |
23 |
Where: |
Where: |
24 |
--keepgoing tells $0 to keep going after an error |
--keepgoing tells $0 to keep going after an error |
25 |
--jobdir dir overrules the default value of the JOBDIR variable |
--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 |
# Parse commandline parameters |
34 |
while [ $# -gt 0 ] |
while [ $# -gt 0 ] |
35 |
do |
do |
36 |
case "$1" in |
case "$1" in |
37 |
(-h|--help) echo "${USAGE}" |
(-h|--help) echo "${USAGE}" |
38 |
exit 0 |
exit 0 |
39 |
;; |
;; |
40 |
(--jobdir) JOBDIR=$2 |
(-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 |
shift |
55 |
;; |
;; |
56 |
(--jobdir=*) JOBDIR=${1##--jobdir=} |
(--jobdir=*) JOBDIR=${1##--jobdir=} |
57 |
;; |
;; |
58 |
(-d|--debug) let DEBUG+=1 |
(--job-dir=*) JOBDIR=${1##--job-dir=} |
59 |
;; |
;; |
60 |
(-q|--quiet) QUIET=1 |
(--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 |
(-k|--keepgoing) KEEPGOING=1 |
(--end=*) END_INDEX=${1##--end=} |
74 |
;; |
;; |
75 |
(-*) echo "Invalid option: $1" |
(-*) echo "Invalid option: $1" |
76 |
exit 1 |
exit 1 |
82 |
# not needed |
# not needed |
83 |
# checkProxy "${vo}" |
# 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 |
# now check all known jobs |
117 |
cd "${JOBDIR}" |
numjobs=0 |
118 |
base="$PWD" |
for jobid in `seq ${START_INDEX} ${END_INDEX}` |
|
for jobdir in [0-9][0-9][0-9][0-9][0-9] |
|
119 |
do |
do |
120 |
cd "${base}/${jobdir}" |
jobdir=`printf "${JOBDIR}/%05d" ${jobid}` |
121 |
if [ -r jobid ] |
|
122 |
|
if [ -r "${jobdir}/jobid" ] |
123 |
then |
then |
124 |
info "DANS-job ${jobdir} found" |
cd "${jobdir}" |
125 |
|
|
126 |
|
info "DANS-job ${jobdir##*/} found" |
127 |
# check for job files |
# check for job files |
128 |
files_found=`(ls -d jdl job*log output 2> /dev/null)` |
files_found=`ls -d jdl job*log output 2> /dev/null` |
129 |
debug " Job files found: " $files_found |
debug " Job files found: " $files_found |
130 |
|
|
131 |
if [ -r jdl ] |
if [ -r jdl ] |
132 |
then |
then |
133 |
|
let numjobs++ |
134 |
# Extract the executable (script) and arguments from the jdl |
# Extract the executable (script) and arguments from the jdl |
135 |
executable=`sed -n 's/^Executable = "\(.*\)".*/\1/p' jdl` |
executable=`sed -n 's/^Executable = "\(.*\)".*/\1/p' jdl` |
136 |
arguments=`sed -n 's/^Arguments = "\(.*\)".*/\1/p' jdl` |
arguments=`sed -n 's/^Arguments = "\(.*\)".*/\1/p' jdl` |
140 |
;; |
;; |
141 |
(compress-archive.sh) jobtype="Compress Archive job (tar->tar.gz)" |
(compress-archive.sh) jobtype="Compress Archive job (tar->tar.gz)" |
142 |
;; |
;; |
143 |
|
(*) jobtype="Unknown" |
144 |
|
;; |
145 |
esac |
esac |
146 |
|
|
147 |
# The arguments should look something like 'Crome X Y' |
# The arguments should look something like 'Crome X Y' |
150 |
end_index=`echo $arguments | awk '{ print $3 }'` |
end_index=`echo $arguments | awk '{ print $3 }'` |
151 |
info " $jobtype Archive=\"$jobarchive\" Start_index=$start_index End_index=$end_index" |
info " $jobtype Archive=\"$jobarchive\" Start_index=$start_index End_index=$end_index" |
152 |
else |
else |
153 |
warn "No jdl file found in ${JOBDIR}/${jobdir}, skipping" |
warn "No jdl file found in ${jobdir}, skipping" |
154 |
fi |
fi |
155 |
# check for a status file |
# check for status file(s) |
156 |
statusfile=`(ls -1 Status=* 2> /dev/null)` |
statusfile=`(ls -1tr Status=* 2> /dev/null)` |
157 |
debug "Status files: " $statusfile |
debug "Status files: " $statusfile |
158 |
|
|
159 |
status="${statusfile#Status=}" |
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 |
case "${status}" in |
166 |
(Submitted) status_line=" Status: Job submitted, waiting for scheduler" |
(Submitted) status_line=" Status: Job submitted, waiting for scheduler" |
167 |
;; |
;; |
176 |
;; |
;; |
177 |
(Aborted) status_line=" Status: Job aborted!" |
(Aborted) status_line=" Status: Job aborted!" |
178 |
;; |
;; |
179 |
|
(Cancelled) status_line=" Status: Job cancelled by user!" |
180 |
|
;; |
181 |
(*) status_line=" Status: unknown! : \"${statusfile}\"" |
(*) status_line=" Status: unknown! : \"${statusfile}\"" |
182 |
;; |
;; |
183 |
esac |
esac |
201 |
eval `echo "$job_log"` |
eval `echo "$job_log"` |
202 |
status_line="${status_line} Exit code=$exitcode Timestamp=$timestamp" |
status_line="${status_line} Exit code=$exitcode Timestamp=$timestamp" |
203 |
else |
else |
204 |
warn "No job-logging-info.log file found in ${JOBDIR}/${jobdir}, skipping" |
warn "No job-logging-info.log file found in ${jobdir}, skipping" |
205 |
fi |
fi |
206 |
fi |
fi |
207 |
info "${status_line}" |
info "${status_line}" |
208 |
fi |
fi |
209 |
done |
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 |
|
|