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

Last change on this file since 8006 was 7954, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 11.4 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#
28# This script handles the subsystem logfiles, which are copied every
29# day automatically from /local/ on pc15 in La Palma to
30# /home/lapalma/transfer/ on coma in the datacenter in 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), Cosy (cosy*.log, cosy*.rep, tpoint*.txt/starg*.txt)
34# AMC (AMC*.log, AMC*.info, AMC*.lut) and CaCo (dc*.txt)
35#
36# the script performs the following steps:
37# ----------------------------------------
38# - filling the information from the *.rbk and *.run files into the DB
39# using the macros filldotrbk.C and filldotrun.C
40# - copying all logfiles to the correct directory:
41# /subsystemdata/subsystem/YYYY/MM/DD/file.*
42# - building the sequences for the standard analysis in the database
43# (for each day of which a file was copied)
44# - if a new catalogfile has been copied, it is installed as standard in the
45# setup directory /magic/datacenter/setup and the new lines are sent to
46# the adresses specified in the script
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 `dirname $0`/sourcefile
60printprocesslog "INFO starting $0"
61program=copyscript
62
63set -C
64
65umask 0002
66
67transdir=/home/lapalma/transfer
68char=24
69datetime=`date +%F-%H-%M-%S`
70lockfile=$lockpath/lock-$program.txt
71
72scriptlog=$runlogpath/$program-$datetime.log
73date >> $scriptlog 2>&1
74
75# check if the script is already running
76checklock >> $scriptlog 2>&1
77
78cd $transdir
79
80#check the checksums, write output into file
81md5sum -c .checksums | tee $transdir/.check >> $scriptlog 2>&1
82
83if ! test -e $transdir/.check
84then
85 echo "couldn't create checkfile -> exit script" >> $scriptlog 2>&1
86 finish >> $scriptlog 2>&1
87else
88 echo "checkfile created" >> $scriptlog 2>&1
89fi
90
91
92ssh lapalma@apollo chmod -R g+w $transdir/* >> $scriptlog 2>&1
93
94
95cd $mars
96
97echo "remove empty directories: " >> $scriptlog 2>&1
98rmdir -pv $transdir/*/* >> $scriptlog 2>&1
99
100#find all dates in transfer-directory
101#dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_*[0-1][0-9]_*[0-3][0-9] | grep -v '.tgz'`
102dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_[0-1][0-9]_[0-3][0-9] | grep -v '.tgz'` >> $scriptlog 2>&1
103if [ "$dates" = "" ]
104then
105 echo "nothing to do -> exit" >> $scriptlog 2>&1
106 finish >> $scriptlog 2>&1
107fi
108
109echo "dates found: "$dates >> $scriptlog 2>&1
110#loop over dates
111for date in ${dates[@]}
112do
113 printprocesslog "INFO processing files for $date"
114 #find all files for this date
115 files=`find $transdir/*/$date/ -name "*.*"` >> $scriptlog 2>&1
116 if [ "$files" = "" ]
117 then
118 echo "no files found for $date" >> $scriptlog 2>&1
119 continue
120 else
121 echo "files found for $date" >> $scriptlog 2>&1
122 fi
123
124 date2=`echo $date | sed -e 's/_/\//g'`
125 copylogpath=$logpath/$program/$date2
126 echo "copylogpath: "$copylogpath >> $scriptlog 2>&1
127 makedir $copylogpath >> $scriptlog 2>&1
128
129 #loop over all files in the directories for this date
130 for file in $files
131 do
132 echo "file: "$file >> $scriptlog 2>&1
133 filename=`basename $file`
134
135 #check for each file whether it has to be processed
136 if grep -i "$filename: OK" $transdir/.check >> $scriptlog 2>&1
137 then
138 newfile=`echo $file | sed -e 's/home\/lapalma\/transfer/magic\/subsystemdata/' -e 's/ccdata/cc/' -e 's/cacodata/caco/' -e 's/drivelogs/drive/' -e 's/_/\//1' -e 's/_/\//1' `
139 echo "file (new path): "$newfile >> $scriptlog 2>&1
140 newpath=`dirname $newfile`
141 #make sure, that the needed directories are available
142 makedir $newpath >> $scriptlog 2>&1
143
144 #run macros if the file is a *.rbk or a *.run file to
145 #fill the information into the db
146 if echo $filename | grep \\\.rbk$ >> $scriptlog 2>&1
147 then
148 echo "found rbk-file $filename" >> $scriptlog 2>&1
149
150 checkfillrbk=`root -q -b $macrospath/filldotrbk.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrbk-$filename-log.txt | intgrep`
151
152 case $checkfillrbk in
153 1) echo " checkfillrbk=$checkfillrbk -> everything ok " >> $scriptlog 2>&1
154 echo " -> go on with copying file" >> $scriptlog 2>&1
155 ;;
156 *) echo " checkfillrbk=$checkfillrbk - Error -> go on with next file" >> $scriptlog 2>&1
157 printprocesslog "ERROR filldotrbk.C failed for $file"
158 continue
159 ;;
160 esac
161 fi
162
163 if echo $file | grep 'CC_.*.run' >> $scriptlog 2>&1 && ! echo $file | grep .run.html >> $scriptlog 2>&1
164 then
165 echo "found run-file $filename" >> $scriptlog 2>&1
166
167 checkfillrun=`root -q -b $macrospath/filldotrun.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrun-$filename-log.txt | intgrep`
168
169 case $checkfillrun in
170 1) echo " checkfillrun=$checkfillrun -> everything ok " >> $scriptlog 2>&1
171 echo " -> insert date in SequenceBuildStatus for $date" >> $scriptlog 2>&1
172
173 checkinsertdate=`root -q -b $macrospath/insertdate.C+\("\"$date\""\) | tee $copylogpath/insertdate-$date-log.txt | intgrep`
174
175 case $checkinsertdate in
176 1) echo "date inserted" >> $scriptlog 2>&1 ;;
177 *) echo " checkinsertdate=$checkinsertdate -> ERROR - insert date didn't work" >> $scriptlog 2>&1
178 printprocesslog "ERROR insertdate.C failed for $date"
179 continue
180 ;;
181 esac
182 echo " -> go on with copying file" >> $scriptlog 2>&1
183 ;;
184 *) echo " checkfillrun=$checkfillrun Error -> go on with next file" >> $scriptlog 2>&1
185 printprocesslog "ERROR filldotrun.C failed for $file"
186 continue
187 ;;
188 esac
189 fi
190
191 if mv -v $file $newpath >> $scriptlog 2>&1
192 then
193 #add file to donelist
194 filename3=`echo $file | cut -c $char-999`
195 echo "$filename3 processed" >> $transdir/.processed
196 echo $filename" moved and added to .processed" >> $scriptlog 2>&1
197 else
198 echo $file" couldn't be moved!!!!!" >> $scriptlog 2>&1
199 printprocesslog "WARN moving of file $file didn't work"
200 fi
201
202 else
203 #if the checksum for the file is not ok or the file was
204 #already processed (entry in donelist) -> go on with next file
205 echo $file": checksum not ok " >> $scriptlog 2>&1
206 printprocesslog "WARN checksum for file $file is not ok"
207 fi
208 done
209done
210
211echo "remove empty directories: " >> $scriptlog 2>&1
212rmdir -pv $transdir/*/* >> $scriptlog 2>&1
213
214rm -v $transdir/.check >> $scriptlog 2>&1
215
216
217
218#second part of the script:
219#update the catalog file magic_favorites.edb
220printprocesslog "INFO processing new catalog files"
221magfav=magic_favorites.edb #catalog filename
222catalog=$setuppath/$magfav #current catalogfile
223diff=$setuppath/.diff #file to store difference
224
225#getting new catalogfiles
226catfiles=`find $subsystempath/cc/ -name $magfav -newer $catalog | sort`
227
228for catfile in ${catfiles[@]}
229do
230 printprocesslog "INFO processing catalog file $catfile"
231 #write information into .diff
232 echo "diff $catfile $catalog" >| $diff
233 diff $catfile $catalog >> $diff
234 #getting differences
235 ins=`cat $diff | grep '>'` #what has been inserted
236 outs=`cat $diff | grep '<'` #what has been removed
237
238 #check if lines have been inserted
239 if ! [ "$ins" == "" ]
240 then
241 echo "--> catalogfile: "$catfile >> $scriptlog 2>&1
242 echo "the following lines were added:" >> $scriptlog 2>&1
243 cat $diff | grep '>' >> $scriptlog 2>&1
244
245 #check if lines have been removed
246 if ! [ "$outs" == "" ]
247 then
248 echo "the following lines have been removed" >> $scriptlog 2>&1
249 cat $diff | grep '<' >> $scriptlog 2>&1
250 echo " -> please check the file $catfile" >> $scriptlog 2>&1
251 #inform $adrs about removed lines
252 nail -s 'catalogfile - removed lines' $adrs < $diff
253 printprocesslog "NEWS catalog file: lines have been removed ($catfile)"
254 finish >> $scriptlog 2>&1
255 fi
256
257 #getting date of new catalogfile from path
258 date=`echo $catfile | cut -d/ -f5-7 | sed -e 's/\///g'`
259
260 oldcatalogpath=$setuppath/oldcatalogs
261 makedir $oldcatalogpath
262 #rsync current catalogfile to directory with old catalogfiles including the date of the new catalogfile into the filename
263 if ! rsync -av $catalog $oldcatalogpath/$magfav.$date >> $scriptlog 2>&1
264 then
265 echo "could not do 'rsync -av $catalog $setuppath/oldcatalogs/$magfav.$date' -> exit" >> $scriptlog 2>&1
266 printprocesslog "ERROR rsync of catalog file ($catalog -> $oldcatalogpath/$magfav.$date) didn't work"
267 finish >> $scriptlog 2>&1
268 fi
269 #rsync new catalogfile to current catalogfile
270 if ! rsync -av $catfile $catalog >> $scriptlog 2>&1
271 then
272 echo "could not do 'rsync -av $catfile $catalog' -> exit" >> $scriptlog 2>&1
273 printprocesslog "ERROR rsync of catalog file ($catfile -> $catalog) didn't work"
274 finish >> $scriptlog 2>&1
275 fi
276 #inform $adrs about changes
277 echo "file has been rsynced sucessfully -> sending email" >> $scriptlog 2>&1
278 nail -s 'new catalogfile installed - new lines' $adrs < $diff
279 printprocesslog "NEWS there are new lines in the catalogfile (see $catalog)"
280 continue
281 fi
282 #check if lines have been removed
283 if ! [ "$outs" == "" ]
284 then
285 echo "the following lines have been removed" >> $scriptlog 2>&1
286 cat $diff | grep '<' >> $scriptlog 2>&1
287 echo " -> please check the file $catfile" >> $scriptlog 2>&1
288 #inform $adrs about removed lines
289 nail -s 'catalogfile - removed lines' $adrs < $diff
290 printprocesslog "NEWS catalog file: lines have been removed ($catfile)"
291 finish >> $scriptlog 2>&1
292 fi
293# echo "nothing has changed ($catfile)" >> $scriptlog 2>&1
294done
295
296finish >> $scriptlog 2>&1
297
Note: See TracBrowser for help on using the repository browser.