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