| 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): Daniela Dorner 09/2006 <mailto:dorner@astro.uni-wuerzburg.de>
|
|---|
| 21 | #
|
|---|
| 22 | # Copyright: MAGIC Software Development, 2000-2007
|
|---|
| 23 | #
|
|---|
| 24 | #
|
|---|
| 25 | # ========================================================================
|
|---|
| 26 | #
|
|---|
| 27 | # This script zips the incoming rawfiles.
|
|---|
| 28 | #
|
|---|
| 29 |
|
|---|
| 30 | source `dirname $0`/sourcefile
|
|---|
| 31 | printprocesslog "INFO starting $0"
|
|---|
| 32 | # to give the possibility to run several zipscripts at the same time,
|
|---|
| 33 | # $1 is added
|
|---|
| 34 | program=zipscript$1
|
|---|
| 35 |
|
|---|
| 36 | set -C
|
|---|
| 37 |
|
|---|
| 38 | rawdatapath=$datapath/rawfiles/
|
|---|
| 39 | files=`find ${rawdatapath}20* -type f -name '*.raw'`
|
|---|
| 40 |
|
|---|
| 41 | scriptlog=$runlogpath/$program-$datetime.log
|
|---|
| 42 | date >> $scriptlog 2>&1
|
|---|
| 43 |
|
|---|
| 44 | # check if script is already running
|
|---|
| 45 | lockfile=$lockpath/lock-$program.txt
|
|---|
| 46 | checklock >> $scriptlog 2>&1
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | if [ "$files" == "" ]
|
|---|
| 50 | then
|
|---|
| 51 | echo "no files to zip" >> $scriptlog 2>&1
|
|---|
| 52 | finish >> $scriptlog 2>&1
|
|---|
| 53 | fi
|
|---|
| 54 |
|
|---|
| 55 | for file in ${files[@]}
|
|---|
| 56 | do
|
|---|
| 57 | echo "processing file $file..." >> $scriptlog 2>&1
|
|---|
| 58 | runno=`basename $file | cut -d_ -f2`
|
|---|
| 59 | query="SELECT fSequenceFirst FROM RunData WHERE fRunNumber="$runno
|
|---|
| 60 | echo " sending query: $query" >> $scriptlog 2>&1
|
|---|
| 61 | if ! seq=`sendquery`
|
|---|
| 62 | then
|
|---|
| 63 | echo "querying seq for run $runno from the db did not work -> continue" >> $scriptlog 2>&1
|
|---|
| 64 | printprocesslog "WARN query $seq for run $runno from the db did not work"
|
|---|
| 65 | continue
|
|---|
| 66 | fi
|
|---|
| 67 | if [ "$seq" == "" ]
|
|---|
| 68 | then
|
|---|
| 69 | echo "no seq found for run $runno -> locking only run..." >> $scriptlog 2>&1
|
|---|
| 70 | seq=$runno
|
|---|
| 71 | fi
|
|---|
| 72 | echo "locking sequence $seq..." >> $scriptlog 2>&1
|
|---|
| 73 | lockfile=$lockpath/calzip$seq.txt
|
|---|
| 74 | checklock continue >> $scriptlog 2>&1
|
|---|
| 75 | query="UPDATE SequenceProcessStatus set fNotZipping=NULL WHERE fSequenceFirst=$seq"
|
|---|
| 76 | echo " sending query: $query" >> $scriptlog 2>&1
|
|---|
| 77 | if ! sendquery
|
|---|
| 78 | then
|
|---|
| 79 | echo "locking $seq for callisto in db did not work ..." >> $scriptlog 2>&1
|
|---|
| 80 | printprocesslog "WARN locking $seq for callisto in db did not work"
|
|---|
| 81 | rm -v $lockfile >> $scriptlog 2>&1
|
|---|
| 82 | continue
|
|---|
| 83 | fi
|
|---|
| 84 | echo "zipping $file ..." >> $scriptlog 2>&1
|
|---|
| 85 | if ssh -xn phoenix nice -n 19 gzip -1f $file >> $scriptlog 2>&1
|
|---|
| 86 | then
|
|---|
| 87 | gzfile=$file".gz"
|
|---|
| 88 | chmod a-w $gzfile >> $scriptlog 2>&1
|
|---|
| 89 | else
|
|---|
| 90 | printprocesslog "WARN zipping $file did not work"
|
|---|
| 91 | fi
|
|---|
| 92 | echo "unlocking sequence $seq..." >> $scriptlog 2>&1
|
|---|
| 93 | query="UPDATE SequenceProcessStatus set fNotZipping=Now() WHERE fSequenceFirst=$seq"
|
|---|
| 94 | echo " sending query: $query" >> $scriptlog 2>&1
|
|---|
| 95 | if ! sendquery
|
|---|
| 96 | then
|
|---|
| 97 | echo "unlocking $seq for callisto in db did not work ..." >> $scriptlog 2>&1
|
|---|
| 98 | printprocesslog "ERROR unlocking $seq for callisto in db did not work"
|
|---|
| 99 | rm -v $lockfile >> $scriptlog 2>&1
|
|---|
| 100 | continue
|
|---|
| 101 | fi
|
|---|
| 102 | rm -v $lockfile >> $scriptlog 2>&1
|
|---|
| 103 | done
|
|---|
| 104 |
|
|---|
| 105 | lockfile=$lockpath/lock-$program.txt
|
|---|
| 106 | finish >> $scriptlog 2>&1
|
|---|
| 107 |
|
|---|