source: tags/Mars-V0.9.5/datacenter/scripts/copyscript

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