source: trunk/MagicSoft/Mars/datacenter/scripts/dbchk@ 9047

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