| 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 | getdbsetup
|
|---|
| 49 | alias mymysql='mysql -s -u $us --password=$pw --host=$ho $db'
|
|---|
| 50 |
|
|---|
| 51 | # check for crashed nights, runs, sequences and datasets
|
|---|
| 52 | printprocesslog "INFO Checking if something is crashed on nightly basis"
|
|---|
| 53 | nights=`echo "SELECT fDate FROM SequenceBuildStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
|
|---|
| 54 | if [ ! "$nights" = "" ]
|
|---|
| 55 | then
|
|---|
| 56 | printprocesslog "WARN For the following nights something seems to be crashed. Please check manually: $nights"
|
|---|
| 57 | else
|
|---|
| 58 | printprocesslog "INFO Nothing found."
|
|---|
| 59 | fi
|
|---|
| 60 |
|
|---|
| 61 | printprocesslog "INFO Checking if something is crashed on run basis"
|
|---|
| 62 | cruns=`echo "SELECT fRunNumber FROM RunProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
|
|---|
| 63 | if [ ! "$cruns" = "" ]
|
|---|
| 64 | then
|
|---|
| 65 | printprocesslog "WARN The following runs seem to be crashed. Please check manually: $cruns"
|
|---|
| 66 | else
|
|---|
| 67 | printprocesslog "INFO Nothing found."
|
|---|
| 68 | fi
|
|---|
| 69 |
|
|---|
| 70 | printprocesslog "INFO Checking if something is crashed on sequence basis"
|
|---|
| 71 | csequences=`echo "SELECT fSequenceFirst FROM SequenceProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
|
|---|
| 72 | if [ ! "$csequences" = "" ]
|
|---|
| 73 | then
|
|---|
| 74 | printprocesslog "WARN The following sequences seem to be crashed. Please check manually: $csequences"
|
|---|
| 75 | else
|
|---|
| 76 | printprocesslog "INFO Nothing found."
|
|---|
| 77 | fi
|
|---|
| 78 |
|
|---|
| 79 | printprocesslog "INFO Checking if something is crashed on dataset basis"
|
|---|
| 80 | cdatasets=`echo "SELECT fDataSetNumber FROM DataSetProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
|
|---|
| 81 | if [ ! "$cdatasets" = "" ]
|
|---|
| 82 | then
|
|---|
| 83 | printprocesslog "WARN The following datasets seem to be crashed. Please check manually: $cdatasets"
|
|---|
| 84 | else
|
|---|
| 85 | printprocesslog "INFO Nothing found."
|
|---|
| 86 | fi
|
|---|
| 87 |
|
|---|
| 88 | # CHECK 1
|
|---|
| 89 | printprocesslog "INFO Checking if all sequence files have a corresponding entry in Sequences"
|
|---|
| 90 | files=`find $sequpath -type f`
|
|---|
| 91 | for file in $files
|
|---|
| 92 | do
|
|---|
| 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
|
|---|
| 106 | done
|
|---|
| 107 |
|
|---|
| 108 | # CHECK 1b (callisto)
|
|---|
| 109 | printprocesslog "INFO Checking if all sequences in ${datapath}/callisto have a corresponding sequence in Sequence"
|
|---|
| 110 | dirs=`find ${datapath}/callisto -mindepth 2 -maxdepth 2 -type d`
|
|---|
| 111 | for dir in $dirs
|
|---|
| 112 | do
|
|---|
| 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
|
|---|
| 126 | done
|
|---|
| 127 |
|
|---|
| 128 | # CHECK 1c (star)
|
|---|
| 129 | printprocesslog "INFO Checking if all sequences in ${datapath}/star have a corresponding sequence in Sequence"
|
|---|
| 130 | dirs=`find ${datapath}/star -mindepth 2 -type d`
|
|---|
| 131 | for dir in $dirs
|
|---|
| 132 | do
|
|---|
| 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
|
|---|
| 146 | done
|
|---|
| 147 |
|
|---|
| 148 | # CHECK 2
|
|---|
| 149 | printprocesslog "INFO Checking if all sequences in Sequences have a corresponding sequence files"
|
|---|
| 150 | sequences=`echo SELECT fSequenceFirst FROM Sequences left join SequenceProcessStatus using (fSequenceFirst,fTelescopeNumber) where not isnull(fSequenceFileWritten) | mymysql`
|
|---|
| 151 | for sequence in $sequences
|
|---|
| 152 | do
|
|---|
| 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
|
|---|
| 158 | done
|
|---|
| 159 |
|
|---|
| 160 | # CHECK 3
|
|---|
| 161 | printprocesslog "INFO Checking if all sequences from Sequences exist RunData"
|
|---|
| 162 | sequences=`echo SELECT fSequenceFirst FROM Sequences GROUP BY fSequenceFirst | mymysql`
|
|---|
| 163 | for sequence in $sequences
|
|---|
| 164 | do
|
|---|
| 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
|
|---|
| 171 | done
|
|---|
| 172 |
|
|---|
| 173 | # CHECK 4
|
|---|
| 174 | printprocesslog "INFO Checking if all sequences from RunData exist in Sequences"
|
|---|
| 175 | sequences=`echo SELECT fSequenceFirst FROM RunData WHERE not fSequenceFirst=0 GROUP BY fSequenceFirst | mymysql`
|
|---|
| 176 | for sequence in $sequences
|
|---|
| 177 | do
|
|---|
| 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
|
|---|
| 184 | done
|
|---|
| 185 |
|
|---|
| 186 | # CHECK 5
|
|---|
| 187 | printprocesslog "INFO Checking if all sequences from RunData exist in SequenceProcessStatus"
|
|---|
| 188 | sequences=`echo SELECT fSequenceFirst FROM RunData WHERE not fSequenceFirst=0 GROUP BY fSequenceFirst | mymysql`
|
|---|
| 189 | for sequence in $sequences
|
|---|
| 190 | do
|
|---|
| 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
|
|---|
| 197 | done
|
|---|
| 198 |
|
|---|
| 199 | finish
|
|---|