Index: trunk/MagicSoft/Mars/datacenter/scripts/dbchk
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/dbchk	(revision 9131)
+++ trunk/MagicSoft/Mars/datacenter/scripts/dbchk	(revision 9355)
@@ -46,53 +46,46 @@
 program=dbchk
 
-scriptlog=$runlogpath/$program-$datetime.log
-date >> $scriptlog 2>&1
-
 getdbsetup
 alias mymysql='mysql -s -u $us --password=$pw --host=$ho $db'
 
 # check for crashed nights, runs, sequences and datasets
-echo "Checking if something is crashed on nightly basis" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if something is crashed on nightly basis" 
 nights=`echo "SELECT fDate FROM SequenceBuildStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
 if [ ! "$nights" = "" ]
 then
    printprocesslog "WARN For the following nights something seems to be crashed. Please check manually: $nights"
-   echo "WARN For the following nights something  seems to be crashed. Please check manually: $nights" >> $scriptlog 2>&1
 else
-   echo " Nothing found." >> $scriptlog 2>&1
+   printprocesslog "INFO Nothing found." 
 fi
 
-echo "Checking if something is crashed on run basis" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if something is crashed on run basis" 
 cruns=`echo "SELECT fRunNumber FROM RunProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
 if [ ! "$cruns" = "" ]
 then
    printprocesslog "WARN The following runs seem to be crashed. Please check manually: $cruns"
-   echo "WARN The following runs seem to be crashed. Please check manually: $cruns" >> $scriptlog 2>&1
 else
-   echo " Nothing found." >> $scriptlog 2>&1
+   printprocesslog "INFO Nothing found." 
 fi
 
-echo "Checking if something is crashed on sequence basis" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if something is crashed on sequence basis" 
 csequences=`echo "SELECT fSequenceFirst FROM SequenceProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()" | mymysql`
 if [ ! "$csequences" = "" ]
 then
    printprocesslog "WARN The following sequences seem to be crashed. Please check manually: $csequences"
-   echo "WARN The following sequences seem to be crashed. Please check manually: $csequences" >> $scriptlog 2>&1
 else
-   echo " Nothing found." >> $scriptlog 2>&1
+   printprocesslog "INFO Nothing found." 
 fi
 
-echo "Checking if something is crashed on dataset basis" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if something is crashed on dataset basis" 
 cdatasets=`echo "SELECT fDataSetNumber FROM DataSetProcessStatus WHERE isnull(fFailedTime) and not isnull(fStartTime) and adddate(fStartTime, Interval 12 HOUR) < Now()"  | mymysql`
 if [ ! "$cdatasets" = "" ]
 then
    printprocesslog "WARN The following datasets seem to be crashed. Please check manually: $cdatasets"
-   echo "WARN The following datasets seem to be crashed. Please check manually: $cdatasets" >> $scriptlog 2>&1
 else
-   echo " Nothing found." >> $scriptlog 2>&1
+   printprocesslog "INFO Nothing found." 
 fi
 
 # CHECK 1
-echo "Checking if all sequence files have a corresponding entry in Sequences" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if all sequence files have a corresponding entry in Sequences" 
 files=`find $sequpath -type f`
 for file in $files
@@ -101,5 +94,4 @@
    if [ "$sequence" = "" ] || [ "$sequence" = "$file" ]
    then
-      echo "No sequence file: $file" >> $scriptlog 2>&1
       printprocesslog "ERROR No sequence file: $file" 
       continue
@@ -109,5 +101,4 @@
    if ! [ "$sequence" = "$var" ]
    then
-      echo "Sequence-File $sequence exist but it is not in Sequences." >> $scriptlog 2>&1
       printprocesslog "ERROR Sequence-File $sequence exists, but it is not in Sequences (DB)." 
       continue
@@ -116,5 +107,5 @@
 
 # CHECK 1b (callisto)
-echo "Checking if all sequences in ${datapath}/callisto have a corresponding sequence in Sequence" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if all sequences in ${datapath}/callisto have a corresponding sequence in Sequence" 
 dirs=`find ${datapath}/callisto -mindepth 2 -maxdepth 2 -type d`
 for dir in $dirs
@@ -123,5 +114,4 @@
    if [ "$sequence" = "" ] || [ "$sequence" = "$dir" ]
    then
-      echo "Invalid directory: $dir" >> $scriptlog 2>&1
       printprocesslog "ERROR Invalid directory: $dir" 
       continue
@@ -131,5 +121,4 @@
    if ! [ "$sequence" = "$var" ]
    then
-      echo "$dir exists but no corresponding sequence in Sequences." >> $scriptlog 2>&1
       printprocesslog "ERROR $dir exists, but no corresponding sequence in Sequences (DB)." 
       continue
@@ -138,5 +127,5 @@
 
 # CHECK 1c (star)
-echo "Checking if all sequences in ${datapath}/star have a corresponding sequence in Sequence" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if all sequences in ${datapath}/star have a corresponding sequence in Sequence" 
 dirs=`find ${datapath}/star -mindepth 2 -type d`
 for dir in $dirs
@@ -145,5 +134,4 @@
    if [ "$sequence" = "" ] || [ "$sequence" = "$dir" ]
    then
-      echo "Invalid directory: $dir" >> $scriptlog 2>&1
       printprocesslog "ERROR Invalid directory: $dir" 
       continue
@@ -153,5 +141,4 @@
    if ! [ "$sequence" = "$var" ]
    then
-      echo "$dir exists but no corresponding sequence in Sequences." >> $scriptlog 2>&1
       printprocesslog "ERROR $dir exists, but no corresponding sequence in Sequences (DB)." 
       continue
@@ -160,5 +147,5 @@
 
 # CHECK 2
-echo "Checking if all sequences in Sequences have a corresponding sequence files" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if all sequences in Sequences have a corresponding sequence files" 
 sequences=`echo SELECT fSequenceFirst FROM Sequences left join SequenceProcessStatus using (fSequenceFirst,fTelescopeNumber) where not isnull(fSequenceFileWritten) | mymysql`
 for sequence in $sequences
@@ -167,5 +154,4 @@
    if [ "$var" = "" ]
    then
-      echo "Sequence-File for $sequence not found but in db." >> $scriptlog 2>&1
       printprocesslog "ERROR Sequence-File for $sequence not found but in DB." 
    fi
@@ -173,5 +159,5 @@
 
 # CHECK 3
-echo "Checking if all sequences from Sequences exist RunData" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if all sequences from Sequences exist RunData" 
 sequences=`echo SELECT fSequenceFirst FROM Sequences GROUP BY fSequenceFirst | mymysql`
 for sequence in $sequences
@@ -180,6 +166,5 @@
    if ! [ "$sequence" = "$res" ]
    then
-      echo "Sequence $sequence exists in Sequences but not in RunData." >> $scriptlog 2>&1
-      printprocesslog "Sequence $sequence exists in Sequences but not in RunData (DB)."
+      printprocesslog "ERROR Sequence $sequence exists in Sequences but not in RunData (DB)."
       continue
    fi
@@ -187,5 +172,5 @@
 
 # CHECK 4
-echo "Checking if all sequences from RunData exist in Sequences" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if all sequences from RunData exist in Sequences" 
 sequences=`echo SELECT fSequenceFirst FROM RunData WHERE not fSequenceFirst=0 GROUP BY fSequenceFirst | mymysql`
 for sequence in $sequences
@@ -194,6 +179,5 @@
    if ! [ "$sequence" = "$var" ]
    then
-      echo "Sequence $sequence exists in RunData but not in Sequences." >> $scriptlog 2>&1
-      printprocesslog "Sequence $sequence exists in RunData but not in Sequences (DB)." 
+      printprocesslog "ERROR Sequence $sequence exists in RunData but not in Sequences (DB)." 
       continue
    fi
@@ -201,5 +185,5 @@
 
 # CHECK 5
-echo "Checking if all sequences from RunData exist in SequenceProcessStatus" >> $scriptlog 2>&1
+printprocesslog "INFO Checking if all sequences from RunData exist in SequenceProcessStatus" 
 sequences=`echo SELECT fSequenceFirst FROM RunData WHERE not fSequenceFirst=0 GROUP BY fSequenceFirst | mymysql`
 for sequence in $sequences
@@ -208,9 +192,8 @@
    if ! [ "$sequence" = "$var" ]
    then
-      echo "Sequence $sequence exists in RunData but not in SequenceProcessStatus." >> $scriptlog 2>&1
-      printprocesslog "Sequence $sequence exists in RunData but not in SequenceProcessStatus (DB)." 
+      printprocesslog "ERROR Sequence $sequence exists in RunData but not in SequenceProcessStatus (DB)." 
       continue
    fi
 done
 
-finish >> $scriptlog 2>&1
+finish 
