source: trunk/MagicSoft/Mars/datacenter/scripts/copyscript@ 7146

Last change on this file since 7146 was 7146, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.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 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
21#
22# Copyright: MAGIC Software Development, 2000-2004
23#
24#
25# ========================================================================
26#
27#
28# This script handles the subsystem logfiles, which are copied every
29# day automatically from pc15 in La Palma to /data/MAGIC/transfer/ in
30# Wuerzburg
31# The structure in this directory is: subsystem/date/logfile.*
32# The logfiles are from CC (*.rep, CC*.dbg, CC*.rbk, CC*.rep, CC*.run,
33# CC*.run.html) and Cosy (cosy*.log, cosy*.rep, tpoint*.txt/starg*.txt)
34# AMC (AMC*.log, AMC*.info, AMC*.lut) and CaCo (dc*.txt) are not copied
35# every day automatically
36#
37# the script performs the following steps:
38# ----------------------------------------
39# - filling the information from the *.rbk and *.run files into the DB
40# using the macros filldotrbk.C and filldotrun.C
41# - copying all logfiles to the correct directory:
42# /Period*/subsystem/date/file.*
43# (the period for each date is obtained by the macro getperiod.C)
44# - filling the sequences for the standard analysis into the database
45# (for each day of which a file was copied)
46#
47#
48# -- to make sure that no file is copied twice there's a textfile
49# (.processed), to which every file, that was processed, is added
50# .processed is copied to La Palma, so that it is possible to copy
51# only new files
52# -- to make sure that a file was copied completely before it is
53# processed, a file with the checksum of all files is also copied from
54# La Palma and the checksum is checked with this script for each file
55# before processing it.
56#
57#
58
59source /home/operator/Mars/datacenter/scripts/sourcefile
60
61set -C
62
63umask 0002
64
65transdir=/home/lapalma/transfer
66char=28
67#extern=MAGIC@virgo:/data/MAGIC/transfer
68datetime=`date +%F-%H-%M-%S`
69
70scriptlogpath=$logpath/run/copyscript/`date +%Y/%m/%d`
71if [ ! -d $scriptlogpath ]
72then
73 mkdir -pv $scriptlogpath
74 if [ ! -d $scriptlogpath ]
75 then
76 echo "could not make scriptlogpath "$scriptlogpath
77 exit
78 fi
79fi
80
81scriptlog=$scriptlogpath/copyscript-$datetime.log
82
83date >> $scriptlog 2>&1
84
85date > $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
86checklock0=$?
87case $checklock0 in
88 0) echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
89 1) echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
90 echo "-> copyscript is running -> exit" >> $scriptlog 2>&1
91 date >> $scriptlog 2>&1
92 exit;;
93 *) echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
94esac
95
96# rsync new dc with virgo
97#rsync -av $extern/ $transdir >> $scriptlog 2>&1
98
99cd $transdir
100
101#check the checksums, write output into file
102md5sum -c .checksums | tee $transdir/.check >> $scriptlog 2>&1
103#md5sum -c $transdir/checksums-test >| $transdir/.check
104if ! test -e $transdir/.check
105then
106 echo "couldn't create checkfile -> exit script" >> $scriptlog 2>&1
107 rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
108 date >> $scriptlog 2>&1
109 exit
110else
111 echo "checkfile created" >> $scriptlog 2>&1
112fi
113
114cd $mars
115
116echo "remove empty directories: " >> $scriptlog 2>&1
117rmdir -pv $transdir/*/* >> $scriptlog 2>&1
118
119#find all dates in transfer-directory
120#dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_*[0-1][0-9]_*[0-3][0-9] | grep -v '.tgz'`
121dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_[0-1][0-9]_[0-3][0-9] | grep -v '.tgz'` >> $scriptlog 2>&1
122
123if [ "$dates" = "" ]
124then
125 echo "nothing to do -> exit" >> $scriptlog 2>&1
126 rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
127 date >> $scriptlog 2>&1
128 exit
129fi
130
131echo "dates found: "$dates >> $scriptlog 2>&1
132
133#loop over dates
134for date in ${dates[@]}
135do
136 #find all files for this date
137 files=`find $transdir/*/$date/ -name "*.*"` >> $scriptlog 2>&1
138 if [ "$files" = "" ]
139 then
140 echo "no files found for $date" >> $scriptlog 2>&1
141 continue
142 else
143 echo "files found for $date" >> $scriptlog 2>&1
144 fi
145
146 date2=`echo $date | sed -e 's/_/\//g'`
147# echo "date2=$date2"
148 copylogpath=$logpath/copyscript/$date2
149 echo "copylogpath: "$copylogpath >> $scriptlog 2>&1
150 if [ ! -d $copylogpath ]
151 then
152 mkdir -pv $copylogpath >> $scriptlog 2>&1
153 if [ ! -d $copylogpath ]
154 then
155 echo "could not make copylogpath $copylogpath -> continue " >> $scriptlog 2>&1
156 continue
157 fi
158 fi
159
160 #loop over all files in the directories for this date
161 for file in $files
162 do
163 echo "file: "$file >> $scriptlog 2>&1
164 filename=`basename $file`
165# echo "filename: "$filename
166
167 #check for each file whether it has to be processed
168 if grep "$filename: OK" $transdir/.check >> $scriptlog 2>&1
169 then
170 newfile=`echo $file | sed -e 's/datacenter\/transfer/subsystemdata/' -e 's/ccdata/cc/' -e 's/cacodata/caco/' -e 's/drivelogs/drive/' -e 's/_/\//1' -e 's/_/\//1' `
171 echo "file (new path): "$newfile >> $scriptlog 2>&1
172 newpath=`dirname $newfile`
173# echo "new path: "$newpath
174 #make sure, that the needed directories are available
175 if [ ! -d $newpath ]
176 then
177 mkdir -pv $newpath >> $scriptlog 2>&1
178 if [ ! -d $newpath ]
179 then
180 echo "could not make path $newpath" >> $scriptlog 2>&1
181 continue
182 fi
183 fi
184
185 #run macros if the file is a *.rbk or a *.run file to
186 #fill the information into the db
187 if echo $filename | grep .rbk >> $scriptlog 2>&1
188 then
189 echo "found rbk-file $filename" >> $scriptlog 2>&1
190 checkfillrbk=`root -q -b $macrospath/filldotrbk.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrbk-$filename-log.txt | grep int | sed -e 's/(int)//'`
191 case $checkfillrbk in
192 1) echo "checkfillrbk=$checkfillrbk -> everything ok " >> $scriptlog 2>&1
193 echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
194 *) echo "checkfillrbk=$checkfillrbk - Error -> go on with next file" >> $scriptlog 2>&1
195 continue;;
196 esac
197 fi
198 if echo $file | grep 'CC_.*.run' >> $scriptlog 2>&1 && ! echo $file | grep .run.html >> $scriptlog 2>&1
199 then
200 echo "found run-file $filename" >> $scriptlog 2>&1
201 checkfillrun=`root -q -b $macrospath/filldotrun.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrun-$filename-log.txt | grep int | sed -e 's/(int)//'`
202 case $checkfillrun in
203 1) echo "checkfillrun=$checkfillrun -> everything ok " >> $scriptlog 2>&1
204 echo "-> insert date in SequenceBuildStatus for $date" >> $scriptlog 2>&1
205# date3=`echo $date | sed -e 's/_/-/g'`
206# echo "date3=$date3"
207 checkinsertdate=`root -q -b $macrospath/insertdate.C+\("\"$date\""\) | tee $copylogpath/insertdate-$date-log.txt | grep int | sed -e 's/(int)//'`
208 case $checkinsertdate in
209 1) echo "date inserted" >> $scriptlog 2>&1 ;;
210 *) echo "checkinsertdate=$checkinsertdate -> ERROR - insert date didn't work" >> $scriptlog 2>&1
211 continue;;
212 esac
213 echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
214 *) echo "checkfillrun=$checkfillrun Error -> go on with next file" >> $scriptlog 2>&1
215 continue;;
216 esac
217 fi
218
219 #copy file
220 if mv -v $file $newpath >> $scriptlog 2>&1
221 then
222 #add file to donelist
223 filename3=`echo $file | cut -c $char-999`
224 echo "$filename3 processed" >> $transdir/.processed
225 echo $filename" moved and added to .processed" >> $scriptlog 2>&1
226 else
227 echo $file" couldn't be moved!!!!!" >> $scriptlog 2>&1
228 fi
229
230 else
231 #if the checksum for the file is not ok or the file was
232 #already processed (entry in donelist) -> go on with next file
233 echo $file": checksum not ok " >> $scriptlog 2>&1
234 fi
235 done
236done
237
238echo "remove empty directories: " >> $scriptlog 2>&1
239rmdir -pv $transdir/*/* >> $scriptlog 2>&1
240
241rm -v $transdir/.check >> $scriptlog 2>&1
242
243#rsync -av $transdir/ $extern >> $scriptlog 2>&1
244#rsync -av --delete $transdir/ $extern >> $scriptlog 2>&1
245
246rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
247date >> $scriptlog 2>&1
248
249set +C
Note: See TracBrowser for help on using the repository browser.