source: trunk/MagicSoft/Mars/datacenter/scripts/movingrawfiles@ 8272

Last change on this file since 8272 was 8234, checked in by snruegam, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 4.2 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 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
21#
22# Copyright: MAGIC Software Development, 2000-2006
23#
24#
25# ========================================================================
26#
27# This script is moving the rawfiles from the directory
28# /magic/datacenter/fromtape/rawdata to the structure
29# /magic/data/rawfiles/YYYY/MM/DD
30#
31
32source `dirname $0`/sourcefile
33printprocesslog "INFO starting $0"
34program=movingrawfiles
35
36set -C
37umask 0002
38
39scriptlog=$runlogpath/$program-$datetime.log
40date >> $scriptlog 2>&1
41
42# check whether script is already running
43lockfile=$lockpath/lock-$program.txt
44checklock >> $scriptlog 2>&1
45
46# change permission for files
47ssh tape@dc07 chmod -R g+w /magic/datacenter/fromtape/rawdata/* >> $scriptlog 2>&1
48# output for chmod with -v or -c (only changes)
49
50printprocesslog "INFO moving directories from fromlapalma to fromtape"
51#find directories which have to be copied
52dirs=`ls /magic/datacenter/fromlapalma/RAWchk/*/*.finished | sed -e 's/RAWchk/RAW/g' | cut -d/ -f1-6`
53if [ ! "$dirs" == "" ]
54then
55 for dir in $dirs
56 do
57 # get number of *.raw files from directory
58 numfiles=`find $dir -type f -name "*.raw" | wc -l`
59
60 # skip empty directories
61 if [ "$numfiles" == "0" ]
62 then
63 continue
64 fi
65
66 # get date from directory name
67 curdate=`echo $dir | cut -d/ -f6- | sed -e 's/_/-/g'`
68
69 getdbsetup
70 # get number of runs on this date from db
71 query="select COUNT(*) from RunData where ADDDATE(fRunStart, Interval 12 hour) like '$curdate %'"
72
73 if ! numruns=`mysql -s -u $us --password=$pw --host=hercules $db -e "$query" | tail -1`
74 then
75 echo "ERROR could not query number of runs from rundb -> continue" >> $scriptlog 2>&1
76 printprocesslog "ERROR could not query number of runs for $curdate from rundb"
77 continue
78 fi
79
80 # Check if number of runs matches. If not, skip this directory
81 if ! [ $numfiles -eq $numruns ]
82 then
83 echo "WARNING" >> $scriptlog 2>&1
84 echo "Expecting $numruns raw-files for $curdate but found only $numfiles" >> $scriptlog 2>&1
85 continue
86 fi
87
88 # check for non-raw-files
89 nonraw=`find $dir -type f ! -name "*.raw"`
90 if [ ! "$nonraw" == "" ]
91 then
92 echo "non-raw-files found in $dir" >> $scriptlog 2>&1
93 printprocesslog "WARNING non-raw-files found in $dir"
94 fi
95
96 # change permission for this directory
97 ssh lapalma@apollo chmod -R g+w $dir >> $scriptlog 2>&1
98 # move directories to the tapedirectory
99 mv -v $dir /magic/datacenter/fromtape/rawdata/ >> $scriptlog 2>&1
100
101 done
102fi
103
104
105# find rawfiles
106rawfiles=`find /magic/datacenter/fromtape/rawdata/ -name '*.*'`
107
108if [ "$rawfiles" == "" ]
109then
110 echo "no files to move -> exit" >> $scriptlog 2>&1
111 finish >> $scriptlog 2>&1
112fi
113
114printprocesslog "INFO moving moving rawfiles to $datapath/rawfiles"
115for rawfile in $rawfiles
116do
117# workaround for rawfiles with wrong timing
118# newrawfile=`echo $rawfile | sed -e 's/center\/fromtape\/rawdata/\/rawfiles-wrong-timing/g' -e 's/_/\//1' -e 's/_/\//1'`
119 newrawfile=`echo $rawfile | sed -e 's/center\/fromtape\/rawdata/\/rawfiles/g' -e 's/_/\//1' -e 's/_/\//1'`
120 newdir=`dirname $newrawfile`
121 makedir $newdir >> $scriptlog 2>&1
122
123 mv -v $rawfile $newrawfile >> $scriptlog 2>&1
124done
125
126rmdir -v /magic/datacenter/fromtape/rawdata/* >> $scriptlog 2>&1
127
128printprocesslog "INFO launching filesondisk"
129echo "launching filesondisk" >> $scriptlog 2>&1
130$scriptspath/filesondisk&
131
132finish >> $scriptlog 2>&1
133
Note: See TracBrowser for help on using the repository browser.