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

Last change on this file since 7455 was 7455, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 11.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 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
59user=`whoami`
60source /home/$user/Mars/datacenter/scripts/sourcefile
61
62set -C
63
64umask 0002
65
66transdir=/home/lapalma/transfer
67char=28
68#extern=MAGIC@virgo:/data/MAGIC/transfer
69datetime=`date +%F-%H-%M-%S`
70
71scriptlogpath=$logpath/run/copyscript/`date +%Y/%m/%d`
72makedir $scriptlogpath
73
74scriptlog=$scriptlogpath/copyscript-$datetime.log
75
76date >> $scriptlog 2>&1
77
78date > $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
79checklock0=$?
80case $checklock0 in
81 0) echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
82 1) echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
83 echo "-> copyscript is running -> exit" >> $scriptlog 2>&1
84 date >> $scriptlog 2>&1
85 exit;;
86 *) echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
87esac
88
89# rsync new dc with virgo
90#rsync -av $extern/ $transdir >> $scriptlog 2>&1
91
92cd $transdir
93
94#check the checksums, write output into file
95md5sum -c .checksums | tee $transdir/.check >> $scriptlog 2>&1
96#md5sum -c $transdir/checksums-test >| $transdir/.check
97if ! test -e $transdir/.check
98then
99 echo "couldn't create checkfile -> exit script" >> $scriptlog 2>&1
100 rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
101 date >> $scriptlog 2>&1
102 exit
103else
104 echo "checkfile created" >> $scriptlog 2>&1
105fi
106
107cd $mars
108
109echo "remove empty directories: " >> $scriptlog 2>&1
110rmdir -pv $transdir/*/* >> $scriptlog 2>&1
111
112#find all dates in transfer-directory
113#dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_*[0-1][0-9]_*[0-3][0-9] | grep -v '.tgz'`
114dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_[0-1][0-9]_[0-3][0-9] | grep -v '.tgz'` >> $scriptlog 2>&1
115
116if [ "$dates" = "" ]
117then
118 echo "nothing to do -> exit" >> $scriptlog 2>&1
119 rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
120 date >> $scriptlog 2>&1
121 exit
122fi
123
124echo "dates found: "$dates >> $scriptlog 2>&1
125
126#loop over dates
127for date in ${dates[@]}
128do
129 #find all files for this date
130 files=`find $transdir/*/$date/ -name "*.*"` >> $scriptlog 2>&1
131 if [ "$files" = "" ]
132 then
133 echo "no files found for $date" >> $scriptlog 2>&1
134 continue
135 else
136 echo "files found for $date" >> $scriptlog 2>&1
137 fi
138
139 date2=`echo $date | sed -e 's/_/\//g'`
140# echo "date2=$date2"
141 copylogpath=$logpath/copyscript/$date2
142 echo "copylogpath: "$copylogpath >> $scriptlog 2>&1
143 makedir $copylogpath >> $scriptlog 2>&1
144
145 #loop over all files in the directories for this date
146 for file in $files
147 do
148 echo "file: "$file >> $scriptlog 2>&1
149 filename=`basename $file`
150# echo "filename: "$filename
151
152 #check for each file whether it has to be processed
153 if grep "$filename: OK" $transdir/.check >> $scriptlog 2>&1
154 then
155 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' `
156 echo "file (new path): "$newfile >> $scriptlog 2>&1
157 newpath=`dirname $newfile`
158 #make sure, that the needed directories are available
159 makedir $newpath >> $scriptlog 2>&1
160
161 #run macros if the file is a *.rbk or a *.run file to
162 #fill the information into the db
163 if echo $filename | grep .rbk >> $scriptlog 2>&1
164 then
165 echo "found rbk-file $filename" >> $scriptlog 2>&1
166 checkfillrbk=`root -q -b $macrospath/filldotrbk.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrbk-$filename-log.txt | grep int | sed -e 's/(int)//'`
167 case $checkfillrbk in
168 1) echo "checkfillrbk=$checkfillrbk -> everything ok " >> $scriptlog 2>&1
169 echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
170 *) echo "checkfillrbk=$checkfillrbk - Error -> go on with next file" >> $scriptlog 2>&1
171 continue;;
172 esac
173 fi
174 if echo $file | grep 'CC_.*.run' >> $scriptlog 2>&1 && ! echo $file | grep .run.html >> $scriptlog 2>&1
175 then
176 echo "found run-file $filename" >> $scriptlog 2>&1
177 checkfillrun=`root -q -b $macrospath/filldotrun.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrun-$filename-log.txt | grep int | sed -e 's/(int)//'`
178 case $checkfillrun in
179 1) echo "checkfillrun=$checkfillrun -> everything ok " >> $scriptlog 2>&1
180 echo "-> insert date in SequenceBuildStatus for $date" >> $scriptlog 2>&1
181# date3=`echo $date | sed -e 's/_/-/g'`
182# echo "date3=$date3"
183 checkinsertdate=`root -q -b $macrospath/insertdate.C+\("\"$date\""\) | tee $copylogpath/insertdate-$date-log.txt | grep int | sed -e 's/(int)//'`
184 case $checkinsertdate in
185 1) echo "date inserted" >> $scriptlog 2>&1 ;;
186 *) echo "checkinsertdate=$checkinsertdate -> ERROR - insert date didn't work" >> $scriptlog 2>&1
187 continue;;
188 esac
189 echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
190 *) echo "checkfillrun=$checkfillrun Error -> go on with next file" >> $scriptlog 2>&1
191 continue;;
192 esac
193 fi
194
195 #copy file
196 totapefile=`echo $file | sed -e 's/home\/lapalma\/transfer/magic\/datacenter\/totape/'`
197 totapepath=`dirname $totapefile`
198 makedir $totapepath >> $scriptlog 2>&1
199 if ! cp -v $file $totapepath >> $scriptlog 2>&1
200 then
201 echo $file" couldn't be copied!!!!!" >> $scriptlog 2>&1
202 fi
203
204 if mv -v $file $newpath >> $scriptlog 2>&1
205 then
206 #add file to donelist
207 filename3=`echo $file | cut -c $char-999`
208 echo "$filename3 processed" >> $transdir/.processed
209 echo $filename" moved and added to .processed" >> $scriptlog 2>&1
210 else
211 echo $file" couldn't be moved!!!!!" >> $scriptlog 2>&1
212 fi
213
214 else
215 #if the checksum for the file is not ok or the file was
216 #already processed (entry in donelist) -> go on with next file
217 echo $file": checksum not ok " >> $scriptlog 2>&1
218 fi
219 done
220done
221
222echo "remove empty directories: " >> $scriptlog 2>&1
223rmdir -pv $transdir/*/* >> $scriptlog 2>&1
224
225rm -v $transdir/.check >> $scriptlog 2>&1
226
227#rsync -av $transdir/ $extern >> $scriptlog 2>&1
228#rsync -av --delete $transdir/ $extern >> $scriptlog 2>&1
229
230
231
232#second part of the script:
233#update the catalog file magic_favorites.edb
234
235magfav=magic_favorites.edb #catalog filename
236catalog=$setuppath/$magfav #current catalogfile
237diff=$setuppath/.diff #file to store difference
238#addresses to which the changes are sent
239adrs="dorner@astro.uni-wuerzburg.de, tbretz@astro.uni-wuerzburg.de, hoehne@astro.uni-wuerzburg.de"
240
241#getting new catalogfiles
242catfiles=`find $subsystempath/cc/ -name $magfav -cnewer $catalog | sort`
243
244for catfile in ${catfiles[@]}
245do
246 #write information into .diff
247 echo "file: "$catfile > $diff
248 diff $catalog $catfile >> $diff
249 #getting differences
250 ins=`cat $diff| grep '>'` #what has been inserted
251 outs=`cat $diff | grep '<'`#what has been removed
252
253 #check if lines have been inserted
254 if ! [ "$ins" == "" ]
255 then
256 echo "--> catalogfile: "$catfile >> $scriptlog 2>&1
257 echo "the following lines were added:" >> $scriptlog 2>&1
258 cat $diff | grep '>' >> $scriptlog 2>&1
259
260 #check if lines have been removed
261 if ! [ "$outs" == "" ]
262 then
263 echo "the following lines have been removed" >> $scriptlog 2>&1
264 cat $diff | grep '<' >> $scriptlog 2>&1
265 echo " -> please check the file $catfile" >> $scriptlog 2>&1
266 #inform $adr about removed lines
267 nail -s 'catalogfile - removed lines' $adrs < $diff
268 exit
269 fi
270
271 #getting date of new catalogfile from path
272 date=`echo $catfile | cut -d/ -f5-7 | sed -e 's/\///g'`
273
274 #rsync current catalogfile to directory with old catalogfiles including the date of the new catalogfile into the filename
275 if ! rsync -av $catalog $setuppath/oldcatalogs/$magfav.$date >> $scriptlog 2>&1
276 then
277 echo "could not do 'rsync -av $catalog $setuppath/oldcatalogs/$magfav.$date' -> exit" >> $scriptlog 2>&1
278 exit
279 fi
280 #rsync new catalogfile to current catalogfile
281 if ! rsync -av $catfile $catalog >> $scriptlog 2>&1
282 then
283 echo "could not do 'rsync -av $catfile $catalog' -> exit" >> $scriptlog 2>&1
284 exit
285 fi
286 #inform $adr about changes
287 echo "file has been rsynced sucessfully -> sending email" >> $scriptlog 2>&1
288 nail -s 'new catalogfile installed - new lines' $adrs < $diff
289 continue
290 fi
291 #check if lines have been removed
292 if ! [ "$outs" == "" ]
293 then
294 echo "the following lines have been removed" >> $scriptlog 2>&1
295 cat $diff | grep '<' >> $scriptlog 2>&1
296 echo " -> please check the file $catfile" >> $scriptlog 2>&1
297 #inform $adr about removed lines
298 nail -s 'catalogfile - removed lines' $adrs < $diff
299 exit
300 fi
301# echo "nothing has changed ($catfile)" >> $scriptlog 2>&1
302done
303
304
305rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
306date >> $scriptlog 2>&1
307
308set +C
Note: See TracBrowser for help on using the repository browser.