1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # ========================================================================
|
---|
4 | #
|
---|
5 | # *
|
---|
6 | # * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
7 | # * Software. It is distributed to you in the hope that it can be a useful
|
---|
8 | # * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
9 | # * It is distributed WITHOUT ANY WARRANTY.
|
---|
10 | # *
|
---|
11 | # * Permission to use, copy, modify and distribute this software and its
|
---|
12 | # * documentation for any purpose is hereby granted without fee,
|
---|
13 | # * provided that the above copyright notice appear in all copies and
|
---|
14 | # * that both that copyright notice and this permission notice appear
|
---|
15 | # * in supporting documentation. It is provided "as is" without express
|
---|
16 | # * or implied warranty.
|
---|
17 | # *
|
---|
18 | #
|
---|
19 | #
|
---|
20 | # Author(s): Thomas Bretz 03/2007 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
21 | # Author(s): Daniela Dorner 02/2008 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
22 | # Author(s): Stefan Ruegamer 02/2008 <mailto:snruegam@astro.uni-wuerzburg.de>
|
---|
23 | #
|
---|
24 | # Copyright: MAGIC Software Development, 2000-2008
|
---|
25 | #
|
---|
26 | #
|
---|
27 | # ========================================================================
|
---|
28 | #
|
---|
29 | # This script searches for crashed runs, sequences or datasets in the db
|
---|
30 | # as well as obsolete or missing sequence files and corresponding callisto
|
---|
31 | # and star folders. In the third and fourth check the consistency between
|
---|
32 | # the Run and Sequence DB is checked.
|
---|
33 | #
|
---|
34 | #
|
---|
35 | # TODO
|
---|
36 | #
|
---|
37 | # Spped up with SQL: FIELD(25123, 1, 2, 3, 4, 5, ..., 1000200);
|
---|
38 | # Cross check sequences in Sequence and other databases
|
---|
39 | # added switch which allows to correct for the problems immediatly
|
---|
40 | # unify the checks (especially 1b and 1c)
|
---|
41 | # for the sequences better use 0* instead of 0+ ?
|
---|
42 |
|
---|
43 |
|
---|
44 | source `dirname $0`/sourcefile
|
---|
45 | printprocesslog "INFO starting $0"
|
---|
46 | program=dbchk
|
---|
47 |
|
---|
48 | scriptlog=$runlogpath/$program-$datetime.log
|
---|
49 | date >> $scriptlog 2>&1
|
---|
50 |
|
---|
51 | getdbsetup
|
---|
52 | alias mymysql='mysql -s -u $us --password=$pw --host=$ho $db'
|
---|
53 |
|
---|
54 | # check for crashed nights, runs, sequences and datasets
|
---|
55 | echo "Checking if something is crashed on nightly basis" >> $scriptlog 2>&1
|
---|
56 | nights=`echo "SELECT fDate FROM SequenceBuildStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
|
---|
57 | if [ ! "$nights" = "" ]
|
---|
58 | then
|
---|
59 | printprocesslog "WARN For the following nights something seems to be crashed. Please check manually: $nights"
|
---|
60 | echo "WARN For the following nights something seems to be crashed. Please check manually: $nights" >> $scriptlog 2>&1
|
---|
61 | else
|
---|
62 | echo " Nothing found." >> $scriptlog 2>&1
|
---|
63 | fi
|
---|
64 |
|
---|
65 | echo "Checking if something is crashed on run basis" >> $scriptlog 2>&1
|
---|
66 | cruns=`echo "SELECT fRunNumber FROM RunProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
|
---|
67 | if [ ! "$cruns" = "" ]
|
---|
68 | then
|
---|
69 | printprocesslog "WARN The following runs seem to be crashed. Please check manually: $cruns"
|
---|
70 | echo "WARN The following runs seem to be crashed. Please check manually: $cruns" >> $scriptlog 2>&1
|
---|
71 | else
|
---|
72 | echo " Nothing found." >> $scriptlog 2>&1
|
---|
73 | fi
|
---|
74 |
|
---|
75 | echo "Checking if something is crashed on sequence basis" >> $scriptlog 2>&1
|
---|
76 | csequences=`echo "SELECT fSequenceFirst FROM SequenceProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
|
---|
77 | if [ ! "$csequences" = "" ]
|
---|
78 | then
|
---|
79 | printprocesslog "WARN The following sequences seem to be crashed. Please check manually: $csequences"
|
---|
80 | echo "WARN The following sequences seem to be crashed. Please check manually: $csequences" >> $scriptlog 2>&1
|
---|
81 | else
|
---|
82 | echo " Nothing found." >> $scriptlog 2>&1
|
---|
83 | fi
|
---|
84 |
|
---|
85 | echo "Checking if something is crashed on dataset basis" >> $scriptlog 2>&1
|
---|
86 | cdatasets=`echo "SELECT fDataSetNumber FROM DataSetProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
|
---|
87 | if [ ! "$cdatasets" = "" ]
|
---|
88 | then
|
---|
89 | printprocesslog "WARN The following datasets seem to be crashed. Please check manually: $cdatasets"
|
---|
90 | echo "WARN The following datasets seem to be crashed. Please check manually: $cdatasets" >> $scriptlog 2>&1
|
---|
91 | else
|
---|
92 | echo " Nothing found." >> $scriptlog 2>&1
|
---|
93 | fi
|
---|
94 |
|
---|
95 | # CHECK 1
|
---|
96 | echo "Checking if all sequence files have a corresponding entry in Sequences" >> $scriptlog 2>&1
|
---|
97 | files=`find $sequpath -type f`
|
---|
98 | for file in $files
|
---|
99 | do
|
---|
100 | sequence=`echo $file | sed -e "s/^.*\/sequence0\+\([0-9]\+\)\.txt$/\1/"`
|
---|
101 | if [ "$sequence" = "" ] || [ "$sequence" = "$file" ]
|
---|
102 | then
|
---|
103 | echo "No sequence file: $file" >> $scriptlog 2>&1
|
---|
104 | printprocesslog "ERROR No sequence file: $file"
|
---|
105 | continue
|
---|
106 | fi
|
---|
107 |
|
---|
108 | var=`echo SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst=$sequence | mymysql`
|
---|
109 | if ! [ "$sequence" = "$var" ]
|
---|
110 | then
|
---|
111 | echo "Sequence-File $sequence exist but it is not in Sequences." >> $scriptlog 2>&1
|
---|
112 | printprocesslog "ERROR Sequence-File $sequence exists, but it is not in Sequences (DB)."
|
---|
113 | continue
|
---|
114 | fi
|
---|
115 | done
|
---|
116 |
|
---|
117 | # CHECK 1b (callisto)
|
---|
118 | echo "Checking if all sequences in ${datapath}/callisto have a corresponding sequence in Sequence" >> $scriptlog 2>&1
|
---|
119 | dirs=`find ${datapath}/callisto -mindepth 2 -maxdepth 2 -type d`
|
---|
120 | for dir in $dirs
|
---|
121 | do
|
---|
122 | sequence=`echo $dir | sed -e "s/^.*\/0\+\([0-9]\+\)$/\1/"`
|
---|
123 | if [ "$sequence" = "" ] || [ "$sequence" = "$dir" ]
|
---|
124 | then
|
---|
125 | echo "Invalid directory: $dir" >> $scriptlog 2>&1
|
---|
126 | printprocesslog "ERROR Invalid directory: $dir"
|
---|
127 | continue
|
---|
128 | fi
|
---|
129 |
|
---|
130 | var=`echo SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst=$sequence | mymysql`
|
---|
131 | if ! [ "$sequence" = "$var" ]
|
---|
132 | then
|
---|
133 | echo "$dir exists but no corresponding sequence in Sequences." >> $scriptlog 2>&1
|
---|
134 | printprocesslog "ERROR $dir exists, but no corresponding sequence in Sequences (DB)."
|
---|
135 | continue
|
---|
136 | fi
|
---|
137 | done
|
---|
138 |
|
---|
139 | # CHECK 1c (star)
|
---|
140 | echo "Checking if all sequences in ${datapath}/star have a corresponding sequence in Sequence" >> $scriptlog 2>&1
|
---|
141 | dirs=`find ${datapath}/star -mindepth 2 -type d`
|
---|
142 | for dir in $dirs
|
---|
143 | do
|
---|
144 | sequence=`echo $dir | sed -e "s/^.*\/0\+\([0-9]\+\)$/\1/"`
|
---|
145 | if [ "$sequence" = "" ] || [ "$sequence" = "$dir" ]
|
---|
146 | then
|
---|
147 | echo "Invalid directory: $dir" >> $scriptlog 2>&1
|
---|
148 | printprocesslog "ERROR Invalid directory: $dir"
|
---|
149 | continue
|
---|
150 | fi
|
---|
151 |
|
---|
152 | var=`echo SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst=$sequence | mymysql`
|
---|
153 | if ! [ "$sequence" = "$var" ]
|
---|
154 | then
|
---|
155 | echo "$dir exists but no corresponding sequence in Sequences." >> $scriptlog 2>&1
|
---|
156 | printprocesslog "ERROR $dir exists, but no corresponding sequence in Sequences (DB)."
|
---|
157 | continue
|
---|
158 | fi
|
---|
159 | done
|
---|
160 |
|
---|
161 | # CHECK 2
|
---|
162 | echo "Checking if all sequences in Sequences have a corresponding sequence files" >> $scriptlog 2>&1
|
---|
163 | sequences=`echo SELECT fSequenceFirst FROM Sequences left join SequenceProcessStatus using (fSequenceFirst,fTelescopeNumber) where not isnull(fSequenceFileWritten) | mymysql`
|
---|
164 | for sequence in $sequences
|
---|
165 | do
|
---|
166 | var=`find $sequpath -type f -regex .*/sequence0+${sequence}\.txt$`
|
---|
167 | if [ "$var" = "" ]
|
---|
168 | then
|
---|
169 | echo "Sequence-File for $sequence not found but in db." >> $scriptlog 2>&1
|
---|
170 | printprocesslog "ERROR Sequence-File for $sequence not found but in DB."
|
---|
171 | fi
|
---|
172 | done
|
---|
173 |
|
---|
174 | # CHECK 3
|
---|
175 | echo "Checking if all sequences from Sequences exist RunData" >> $scriptlog 2>&1
|
---|
176 | sequences=`echo SELECT fSequenceFirst FROM Sequences GROUP BY fSequenceFirst | mymysql`
|
---|
177 | for sequence in $sequences
|
---|
178 | do
|
---|
179 | res=`echo SELECT fSequenceFirst FROM RunData WHERE fSequenceFirst=$sequence GROUP BY fSequenceFirst | mymysql`
|
---|
180 | if ! [ "$sequence" = "$res" ]
|
---|
181 | then
|
---|
182 | echo "Sequence $sequence exists in Sequences but not in RunData." >> $scriptlog 2>&1
|
---|
183 | printprocesslog "Sequence $sequence exists in Sequences but not in RunData (DB)."
|
---|
184 | continue
|
---|
185 | fi
|
---|
186 | done
|
---|
187 |
|
---|
188 | # CHECK 4
|
---|
189 | echo "Checking if all sequences from RunData exist in Sequences" >> $scriptlog 2>&1
|
---|
190 | sequences=`echo SELECT fSequenceFirst FROM RunData WHERE not fSequenceFirst=0 GROUP BY fSequenceFirst | mymysql`
|
---|
191 | for sequence in $sequences
|
---|
192 | do
|
---|
193 | var=`echo SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst=$sequence | mymysql`
|
---|
194 | if ! [ "$sequence" = "$var" ]
|
---|
195 | then
|
---|
196 | echo "Sequence $sequence exists in RunData but not in Sequences." >> $scriptlog 2>&1
|
---|
197 | printprocesslog "Sequence $sequence exists in RunData but not in Sequences (DB)."
|
---|
198 | continue
|
---|
199 | fi
|
---|
200 | done
|
---|
201 |
|
---|
202 | # CHECK 5
|
---|
203 | echo "Checking if all sequences from RunData exist in SequenceProcessStatus" >> $scriptlog 2>&1
|
---|
204 | sequences=`echo SELECT fSequenceFirst FROM RunData WHERE not fSequenceFirst=0 GROUP BY fSequenceFirst | mymysql`
|
---|
205 | for sequence in $sequences
|
---|
206 | do
|
---|
207 | var=`echo SELECT fSequenceFirst FROM SequenceProcessStatus WHERE fSequenceFirst=$sequence | mymysql`
|
---|
208 | if ! [ "$sequence" = "$var" ]
|
---|
209 | then
|
---|
210 | echo "Sequence $sequence exists in RunData but not in SequenceProcessStatus." >> $scriptlog 2>&1
|
---|
211 | printprocesslog "Sequence $sequence exists in RunData but not in SequenceProcessStatus (DB)."
|
---|
212 | continue
|
---|
213 | fi
|
---|
214 | done
|
---|
215 |
|
---|
216 | finish >> $scriptlog 2>&1
|
---|