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

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