source: trunk/Mars/datacenter/scripts/dbchk@ 12582

Last change on this file since 12582 was 9355, checked in by Daniela Dorner, 16 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.4 KB
Line 
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
44source `dirname $0`/sourcefile
45printprocesslog "INFO starting $0"
46program=dbchk
47
48getdbsetup
49alias mymysql='mysql -s -u $us --password=$pw --host=$ho $db'
50
51# check for crashed nights, runs, sequences and datasets
52printprocesslog "INFO Checking if something is crashed on nightly basis"
53nights=`echo "SELECT fDate FROM SequenceBuildStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
54if [ ! "$nights" = "" ]
55then
56 printprocesslog "WARN For the following nights something seems to be crashed. Please check manually: $nights"
57else
58 printprocesslog "INFO Nothing found."
59fi
60
61printprocesslog "INFO Checking if something is crashed on run basis"
62cruns=`echo "SELECT fRunNumber FROM RunProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
63if [ ! "$cruns" = "" ]
64then
65 printprocesslog "WARN The following runs seem to be crashed. Please check manually: $cruns"
66else
67 printprocesslog "INFO Nothing found."
68fi
69
70printprocesslog "INFO Checking if something is crashed on sequence basis"
71csequences=`echo "SELECT fSequenceFirst FROM SequenceProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
72if [ ! "$csequences" = "" ]
73then
74 printprocesslog "WARN The following sequences seem to be crashed. Please check manually: $csequences"
75else
76 printprocesslog "INFO Nothing found."
77fi
78
79printprocesslog "INFO Checking if something is crashed on dataset basis"
80cdatasets=`echo "SELECT fDataSetNumber FROM DataSetProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
81if [ ! "$cdatasets" = "" ]
82then
83 printprocesslog "WARN The following datasets seem to be crashed. Please check manually: $cdatasets"
84else
85 printprocesslog "INFO Nothing found."
86fi
87
88# CHECK 1
89printprocesslog "INFO Checking if all sequence files have a corresponding entry in Sequences"
90files=`find $sequpath -type f`
91for file in $files
92do
93 sequence=`echo $file | sed -e "s/^.*\/sequence0\+\([0-9]\+\)\.txt$/\1/"`
94 if [ "$sequence" = "" ] || [ "$sequence" = "$file" ]
95 then
96 printprocesslog "ERROR No sequence file: $file"
97 continue
98 fi
99
100 var=`echo SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst=$sequence | mymysql`
101 if ! [ "$sequence" = "$var" ]
102 then
103 printprocesslog "ERROR Sequence-File $sequence exists, but it is not in Sequences (DB)."
104 continue
105 fi
106done
107
108# CHECK 1b (callisto)
109printprocesslog "INFO Checking if all sequences in ${datapath}/callisto have a corresponding sequence in Sequence"
110dirs=`find ${datapath}/callisto -mindepth 2 -maxdepth 2 -type d`
111for dir in $dirs
112do
113 sequence=`echo $dir | sed -e "s/^.*\/0\+\([0-9]\+\)$/\1/"`
114 if [ "$sequence" = "" ] || [ "$sequence" = "$dir" ]
115 then
116 printprocesslog "ERROR Invalid directory: $dir"
117 continue
118 fi
119
120 var=`echo SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst=$sequence | mymysql`
121 if ! [ "$sequence" = "$var" ]
122 then
123 printprocesslog "ERROR $dir exists, but no corresponding sequence in Sequences (DB)."
124 continue
125 fi
126done
127
128# CHECK 1c (star)
129printprocesslog "INFO Checking if all sequences in ${datapath}/star have a corresponding sequence in Sequence"
130dirs=`find ${datapath}/star -mindepth 2 -type d`
131for dir in $dirs
132do
133 sequence=`echo $dir | sed -e "s/^.*\/0\+\([0-9]\+\)$/\1/"`
134 if [ "$sequence" = "" ] || [ "$sequence" = "$dir" ]
135 then
136 printprocesslog "ERROR Invalid directory: $dir"
137 continue
138 fi
139
140 var=`echo SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst=$sequence | mymysql`
141 if ! [ "$sequence" = "$var" ]
142 then
143 printprocesslog "ERROR $dir exists, but no corresponding sequence in Sequences (DB)."
144 continue
145 fi
146done
147
148# CHECK 2
149printprocesslog "INFO Checking if all sequences in Sequences have a corresponding sequence files"
150sequences=`echo SELECT fSequenceFirst FROM Sequences left join SequenceProcessStatus using (fSequenceFirst,fTelescopeNumber) where not isnull(fSequenceFileWritten) | mymysql`
151for sequence in $sequences
152do
153 var=`find $sequpath -type f -regex .*/sequence0+${sequence}\.txt$`
154 if [ "$var" = "" ]
155 then
156 printprocesslog "ERROR Sequence-File for $sequence not found but in DB."
157 fi
158done
159
160# CHECK 3
161printprocesslog "INFO Checking if all sequences from Sequences exist RunData"
162sequences=`echo SELECT fSequenceFirst FROM Sequences GROUP BY fSequenceFirst | mymysql`
163for sequence in $sequences
164do
165 res=`echo SELECT fSequenceFirst FROM RunData WHERE fSequenceFirst=$sequence GROUP BY fSequenceFirst | mymysql`
166 if ! [ "$sequence" = "$res" ]
167 then
168 printprocesslog "ERROR Sequence $sequence exists in Sequences but not in RunData (DB)."
169 continue
170 fi
171done
172
173# CHECK 4
174printprocesslog "INFO Checking if all sequences from RunData exist in Sequences"
175sequences=`echo SELECT fSequenceFirst FROM RunData WHERE not fSequenceFirst=0 GROUP BY fSequenceFirst | mymysql`
176for sequence in $sequences
177do
178 var=`echo SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst=$sequence | mymysql`
179 if ! [ "$sequence" = "$var" ]
180 then
181 printprocesslog "ERROR Sequence $sequence exists in RunData but not in Sequences (DB)."
182 continue
183 fi
184done
185
186# CHECK 5
187printprocesslog "INFO Checking if all sequences from RunData exist in SequenceProcessStatus"
188sequences=`echo SELECT fSequenceFirst FROM RunData WHERE not fSequenceFirst=0 GROUP BY fSequenceFirst | mymysql`
189for sequence in $sequences
190do
191 var=`echo SELECT fSequenceFirst FROM SequenceProcessStatus WHERE fSequenceFirst=$sequence | mymysql`
192 if ! [ "$sequence" = "$var" ]
193 then
194 printprocesslog "ERROR Sequence $sequence exists in RunData but not in SequenceProcessStatus (DB)."
195 continue
196 fi
197done
198
199finish
Note: See TracBrowser for help on using the repository browser.