source: trunk/MagicSoft/Mars/datacenter/scripts/zipscript@ 9107

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