Index: trunk/MagicSoft/Mars/datacenter/scripts/zipscript
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/zipscript	(revision 9093)
+++ trunk/MagicSoft/Mars/datacenter/scripts/zipscript	(revision 9114)
@@ -19,4 +19,5 @@
 #
 #   Author(s): Daniela Dorner  09/2006 <mailto:dorner@astro.uni-wuerzburg.de>
+#   Author(s): Stefan Ruegamer 08/2008 <mailto:snruegam@astro.uni-wuerzburg.de>
 #
 #   Copyright: MAGIC Software Development, 2000-2007
@@ -55,5 +56,10 @@
 for file in ${files[@]}
 do
-   echo "processing file $file..." >> $scriptlog 2>&1 
+   if ! [ -f $file ]
+   then
+      continue
+   fi
+   
+   echo -e "\nprocessing file $file..." >> $scriptlog 2>&1 
    runno=`basename $file | sed -e 's/.*20[01][0-9]\{5\}_\(M[12]_\)\?.*\([0-9]\{8\}\).\([0-9]\{3\}\)\?.*/\2/'`
    fileno=`basename $file | sed -e 's/.*20[01][0-9]\{5\}_\(M[12]_\)\?.*\([0-9]\{8\}\).\([0-9]\{3\}\)\?.*/\3/'`
@@ -69,29 +75,37 @@
       telno=1
    fi
+   
+   # get the sequence corresponding to the run
    query="SELECT fSequenceFirst FROM RunData WHERE fRunNumber="$runno" AND fFileNumber="$fileno" AND fTelescopeNumber="$telno
-   echo " sending query: $query" >> $scriptlog 2>&1 
+   echo " sending query: $query" >> $scriptlog 2>&1
    if ! seq=`sendquery`
    then
-      echo "querying seq for run M_${telno}${runno}.${fileno} from the db did not work -> continue" >> $scriptlog 2>&1
-      printprocesslog "WARN query $seq for run M_${telno}${runno}.${fileno} from the db did not work"
+      echo "querying seq for run M${telno}_${runno}.${fileno} from the db did not work -> continue" >> $scriptlog 2>&1
+      printprocesslog "WARN query $seq for run M${telno}_${runno}.${fileno} from the db did not work"
       continue
    fi
-   if [ "$seq" == "" ] 
+   if [ "$seq" == "" ] || [ "$seq" == "0" ]
    then
-      echo "no seq found for run M_${telno}${runno}.${fileno} -> locking only run..." >> $scriptlog 2>&1
-      seq=$runno
+      echo "no seq found for run M${telno}_${runno}.${fileno} -> locking only run..." >> $scriptlog 2>&1
+      seq=${runno}.${fileno}
    fi
-   echo "locking sequence $seq..."  >> $scriptlog 2>&1 
+   
+   # lock the sequence against zipscript
+   echo "locking sequence ${seq}-${telno}..."  >> $scriptlog 2>&1
    lockfile=$lockpath/calzip${seq}-${telno}.txt
    checklock continue >> $scriptlog 2>&1
-   query="UPDATE SequenceProcessStatus set fNotZipping=NULL WHERE fSequenceFirst=$seq"
-   echo " sending query: $query" >> $scriptlog 2>&1 
+   
+   # lock the run in the db
+   query="UPDATE SequenceProcessStatus set fNotZipping=NULL WHERE fSequenceFirst=$seq AND fTelescopeNumber=$telno"
+   echo " sending query: $query" >> $scriptlog 2>&1
    if ! sendquery 
    then
-      echo "locking $seq for callisto in db did not work ..." >> $scriptlog 2>&1
-      printprocesslog "WARN locking $seq for callisto in db did not work"
+      echo "locking ${seq}-${telno} for callisto in db did not work ..." >> $scriptlog 2>&1
+      printprocesslog "WARN locking ${seq}-${telno} for callisto in db did not work"
       rm -v $lockfile >> $scriptlog 2>&1
       continue
    fi
+   
+   # zip the run
    echo "zipping $file ..." >> $scriptlog 2>&1
    if ssh -xn phoenix nice -n 19 gzip -1f $file >> $scriptlog 2>&1
@@ -102,11 +116,13 @@
       printprocesslog "WARN zipping $file did not work"
    fi
-   echo "unlocking sequence $seq..."  >> $scriptlog 2>&1 
-   query="UPDATE SequenceProcessStatus set fNotZipping=Now() WHERE fSequenceFirst=$seq"
-   echo " sending query: $query" >> $scriptlog 2>&1 
+   
+   # unlock the sequence in the db
+   echo "unlocking sequence ${seq}-${telno}..."  >> $scriptlog 2>&1
+   query="UPDATE SequenceProcessStatus set fNotZipping=Now() WHERE fSequenceFirst=$seq AND fTelescopeNumber=$telno"
+   echo " sending query: $query" >> $scriptlog 2>&1
    if ! sendquery 
    then
-      echo "unlocking $seq for callisto in db did not work ..." >> $scriptlog 2>&1
-      printprocesslog "ERROR unlocking $seq for callisto in db did not work"
+      echo "unlocking ${seq}-${telno} for callisto in db did not work ..." >> $scriptlog 2>&1
+      printprocesslog "ERROR unlocking ${seq}-${telno} for callisto in db did not work"
       rm -v $lockfile >> $scriptlog 2>&1
       continue
