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

Last change on this file since 6999 was 6999, checked in by Daniela Dorner, 20 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.3 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
59export ROOTSYS=/opt/root_v3.10.02
60export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
61export PATH=$PATH:$ROOTSYS/bin
62
63set -C
64
65umask 0002
66
67mars=/home/operator/Mars
68macrospath=$mars/datacenter/macros
69scriptspath=$mars/datacenter/scripts
70transdir=/magic/datacenter/transfer
71char=28
72extern=MAGIC@virgo:/data/MAGIC/transfer
73datetime=`date +%F-%H-%M-%S`
74
75lockpath=/magic/datacenter/locks
76logpath=/magic/datacenter/autologs
77
78scriptlogpath=$logpath/run/copyscript/`date +%Y/%m/%d`
79if [ ! -d $scriptlogpath ]
80then
81 mkdir -pv $scriptlogpath
82 if [ ! -d $scriptlogpath ]
83 then
84 echo "could not make scriptlogpath "$scriptlogpath
85 exit
86 fi
87fi
88
89scriptlog=$scriptlogpath/copyscript-$datetime.log
90
91date >> $scriptlog 2>&1
92
93date > $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
94checklock0=$?
95case $checklock0 in
96 0) echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
97 1) echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
98 echo "-> copyscript is running -> exit" >> $scriptlog 2>&1
99 date >> $scriptlog 2>&1
100 exit;;
101 *) echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
102esac
103
104# rsync new dc with virgo
105rsync -av $extern/ $transdir >> $scriptlog 2>&1
106
107cd $transdir
108
109#check the checksums, write output into file
110md5sum -c .checksums | tee $transdir/.check >> $scriptlog 2>&1
111#md5sum -c $transdir/checksums-test >| $transdir/.check
112if ! test -e $transdir/.check
113then
114 echo "couldn't create checkfile -> exit script" >> $scriptlog 2>&1
115 rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
116 date >> $scriptlog 2>&1
117 exit
118else
119 echo "checkfile created" >> $scriptlog 2>&1
120fi
121
122cd $mars
123
124echo "remove empty directories: " >> $scriptlog 2>&1
125rmdir -pv $transdir/*/* >> $scriptlog 2>&1
126
127#find all dates in transfer-directory
128#dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_*[0-1][0-9]_*[0-3][0-9] | grep -v '.tgz'`
129dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_[0-1][0-9]_[0-3][0-9] | grep -v '.tgz'` >> $scriptlog 2>&1
130
131if [ "$dates" = "" ]
132then
133 echo "nothing to do -> exit" >> $scriptlog 2>&1
134 rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
135 date >> $scriptlog 2>&1
136 exit
137fi
138
139echo "dates found: "$dates >> $scriptlog 2>&1
140
141#loop over dates
142for date in ${dates[@]}
143do
144 #find all files for this date
145 files=`find $transdir/*/$date/ -name "*.*"` >> $scriptlog 2>&1
146 if [ "$files" = "" ]
147 then
148 echo "no files found for $date" >> $scriptlog 2>&1
149 continue
150 else
151 echo "files found for $date" >> $scriptlog 2>&1
152 fi
153
154 date2=`echo $date | sed -e 's/_/\//g'`
155# echo "date2=$date2"
156 copylogpath=$logpath/copyscript/$date2
157 echo "copylogpath: "$copylogpath >> $scriptlog 2>&1
158 if [ ! -d $copylogpath ]
159 then
160 mkdir -pv $copylogpath >> $scriptlog 2>&1
161 if [ ! -d $copylogpath ]
162 then
163 echo "could not make copylogpath $copylogpath -> continue " >> $scriptlog 2>&1
164 continue
165 fi
166 fi
167
168 #loop over all files in the directories for this date
169 for file in $files
170 do
171 echo "file: "$file >> $scriptlog 2>&1
172 filename=`basename $file`
173# echo "filename: "$filename
174
175 #check for each file whether it has to be processed
176 if grep "$filename: OK" $transdir/.check >> $scriptlog 2>&1
177 then
178 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' `
179 echo "file (new path): "$newfile >> $scriptlog 2>&1
180 newpath=`dirname $newfile`
181# echo "new path: "$newpath
182 #make sure, that the needed directories are available
183 if [ ! -d $newpath ]
184 then
185 mkdir -pv $newpath >> $scriptlog 2>&1
186 if [ ! -d $newpath ]
187 then
188 echo "could not make path $newpath" >> $scriptlog 2>&1
189 continue
190 fi
191 fi
192
193 #run macros if the file is a *.rbk or a *.run file to
194 #fill the information into the db
195 if echo $filename | grep .rbk >> $scriptlog 2>&1
196 then
197 echo "found rbk-file $filename" >> $scriptlog 2>&1
198 checkfillrbk=`root -q -b $macrospath/filldotrbk.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrbk-$filename-log.txt | grep int | sed -e 's/(int)//'`
199 case $checkfillrbk in
200 1) echo "checkfillrbk=$checkfillrbk -> everything ok " >> $scriptlog 2>&1
201 echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
202 *) echo "checkfillrbk=$checkfillrbk - Error -> go on with next file" >> $scriptlog 2>&1
203 continue;;
204 esac
205 fi
206 if echo $file | grep 'CC_.*.run' >> $scriptlog 2>&1 && ! echo $file | grep .run.html >> $scriptlog 2>&1
207 then
208 echo "found run-file $filename" >> $scriptlog 2>&1
209 checkfillrun=`root -q -b $macrospath/filldotrun.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrun-$filename-log.txt | grep int | sed -e 's/(int)//'`
210 case $checkfillrun in
211 1) echo "checkfillrun=$checkfillrun -> everything ok " >> $scriptlog 2>&1
212 echo "-> insert date in SequenceBuildStatus for $date" >> $scriptlog 2>&1
213# date3=`echo $date | sed -e 's/_/-/g'`
214# echo "date3=$date3"
215 checkinsertdate=`root -q -b $macrospath/insertdate.C+\("\"$date\""\) | tee $copylogpath/insertdate-$date-log.txt | grep int | sed -e 's/(int)//'`
216 case $checkinsertdate in
217 1) echo "date inserted" >> $scriptlog 2>&1 ;;
218 *) echo "checkinsertdate=$checkinsertdate -> ERROR - insert date didn't work" >> $scriptlog 2>&1
219 continue;;
220 esac
221 echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
222 *) echo "checkfillrun=$checkfillrun Error -> go on with next file" >> $scriptlog 2>&1
223 continue;;
224 esac
225 fi
226
227 #copy file
228 if mv -v $file $newpath >> $scriptlog 2>&1
229 then
230 #add file to donelist
231 filename3=`echo $file | cut -c $char-999`
232 echo "$filename3 processed" >> $transdir/.processed
233 echo $filename" moved and added to .processed" >> $scriptlog 2>&1
234 else
235 echo $file" couldn't be moved!!!!!" >> $scriptlog 2>&1
236 fi
237
238 else
239 #if the checksum for the file is not ok or the file was
240 #already processed (entry in donelist) -> go on with next file
241 echo $file": checksum not ok " >> $scriptlog 2>&1
242 fi
243 done
244done
245
246echo "remove empty directories: " >> $scriptlog 2>&1
247rmdir -pv $transdir/*/* >> $scriptlog 2>&1
248
249rm -v $transdir/.check >> $scriptlog 2>&1
250
251#rsync -av $transdir/ $extern >> $scriptlog 2>&1
252rsync -av --delete $transdir/ $extern >> $scriptlog 2>&1
253
254rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
255date >> $scriptlog 2>&1
256
257set +C
Note: See TracBrowser for help on using the repository browser.