source: trunk/Mars/datacenter/scripts/zipscript@ 13248

Last change on this file since 13248 was 9114, checked in by snruegam, 16 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 4.5 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): Daniela Dorner 09/2006 <mailto:dorner@astro.uni-wuerzburg.de>
21# Author(s): Stefan Ruegamer 08/2008 <mailto:snruegam@astro.uni-wuerzburg.de>
22#
23# Copyright: MAGIC Software Development, 2000-2007
24#
25#
26# ========================================================================
27#
28# This script zips the incoming rawfiles.
29#
30
31source `dirname $0`/sourcefile
32printprocesslog "INFO starting $0"
33# to give the possibility to run several zipscripts at the same time,
34# $1 is added
35program=zipscript$1
36
37set -C
38
39rawdatapath=$datapath/rawfiles/
40files=`find ${rawdatapath}20* -type f -name '*.raw'`
41
42scriptlog=$runlogpath/$program-$datetime.log
43date >> $scriptlog 2>&1
44
45# check if script is already running
46lockfile=$lockpath/lock-$program.txt
47checklock >> $scriptlog 2>&1
48
49
50if [ "$files" == "" ]
51then
52 echo "no files to zip" >> $scriptlog 2>&1
53 finish >> $scriptlog 2>&1
54fi
55
56for file in ${files[@]}
57do
58 if ! [ -f $file ]
59 then
60 continue
61 fi
62
63 echo -e "\nprocessing file $file..." >> $scriptlog 2>&1
64 runno=`basename $file | sed -e 's/.*20[01][0-9]\{5\}_\(M[12]_\)\?.*\([0-9]\{8\}\).\([0-9]\{3\}\)\?.*/\2/'`
65 fileno=`basename $file | sed -e 's/.*20[01][0-9]\{5\}_\(M[12]_\)\?.*\([0-9]\{8\}\).\([0-9]\{3\}\)\?.*/\3/'`
66 telno=`basename $file | sed -e 's/.*20[01][0-9]\{5\}_\(M[12]_\)\?.*\([0-9]\{8\}\).\([0-9]\{3\}\)\?.*/\1/' | cut -c2`
67 # old runs have a fileno of 0
68 if [ "$fileno" == "" ]
69 then
70 fileno=0
71 fi
72 # old runs have a telno of 1
73 if [ "$telno" == "" ]
74 then
75 telno=1
76 fi
77
78 # get the sequence corresponding to the run
79 query="SELECT fSequenceFirst FROM RunData WHERE fRunNumber="$runno" AND fFileNumber="$fileno" AND fTelescopeNumber="$telno
80 echo " sending query: $query" >> $scriptlog 2>&1
81 if ! seq=`sendquery`
82 then
83 echo "querying seq for run M${telno}_${runno}.${fileno} from the db did not work -> continue" >> $scriptlog 2>&1
84 printprocesslog "WARN query $seq for run M${telno}_${runno}.${fileno} from the db did not work"
85 continue
86 fi
87 if [ "$seq" == "" ] || [ "$seq" == "0" ]
88 then
89 echo "no seq found for run M${telno}_${runno}.${fileno} -> locking only run..." >> $scriptlog 2>&1
90 seq=${runno}.${fileno}
91 fi
92
93 # lock the sequence against zipscript
94 echo "locking sequence ${seq}-${telno}..." >> $scriptlog 2>&1
95 lockfile=$lockpath/calzip${seq}-${telno}.txt
96 checklock continue >> $scriptlog 2>&1
97
98 # lock the run in the db
99 query="UPDATE SequenceProcessStatus set fNotZipping=NULL WHERE fSequenceFirst=$seq AND fTelescopeNumber=$telno"
100 echo " sending query: $query" >> $scriptlog 2>&1
101 if ! sendquery
102 then
103 echo "locking ${seq}-${telno} for callisto in db did not work ..." >> $scriptlog 2>&1
104 printprocesslog "WARN locking ${seq}-${telno} for callisto in db did not work"
105 rm -v $lockfile >> $scriptlog 2>&1
106 continue
107 fi
108
109 # zip the run
110 echo "zipping $file ..." >> $scriptlog 2>&1
111 if ssh -xn phoenix nice -n 19 gzip -1f $file >> $scriptlog 2>&1
112 then
113 gzfile=$file".gz"
114 chmod a-w $gzfile >> $scriptlog 2>&1
115 else
116 printprocesslog "WARN zipping $file did not work"
117 fi
118
119 # unlock the sequence in the db
120 echo "unlocking sequence ${seq}-${telno}..." >> $scriptlog 2>&1
121 query="UPDATE SequenceProcessStatus set fNotZipping=Now() WHERE fSequenceFirst=$seq AND fTelescopeNumber=$telno"
122 echo " sending query: $query" >> $scriptlog 2>&1
123 if ! sendquery
124 then
125 echo "unlocking ${seq}-${telno} for callisto in db did not work ..." >> $scriptlog 2>&1
126 printprocesslog "ERROR unlocking ${seq}-${telno} for callisto in db did not work"
127 rm -v $lockfile >> $scriptlog 2>&1
128 continue
129 fi
130 rm -v $lockfile >> $scriptlog 2>&1
131done
132
133lockfile=$lockpath/lock-$program.txt
134finish >> $scriptlog 2>&1
135
Note: See TracBrowser for help on using the repository browser.