source: trunk/DataCheck/Transfer/ZipRawData.sh@ 14788

Last change on this file since 14788 was 14757, checked in by Daniela Dorner, 12 years ago
inverted order of dates (change from months ago)
  • Property svn:executable set to *
File size: 5.2 KB
Line 
1#!/bin/bash
2
3# this script has been written to run on La Palma on the machine data
4# i.e. paths are only working on this machine
5
6source `dirname $0`/../Sourcefile.sh
7printprocesslog "INFO starting "$0
8
9logfile=$runlogpath"/ZipRawLP-"$datetime".log"
10date >> $logfile
11
12# get last 3, 6 or 9 nights
13dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
14# `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
15# `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
16 )
17
18# get last 3, 6 or 9 nights
19dates=(
20 `date +%Y/%m/%d --date="-204hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-156hour"` \
21 `date +%Y/%m/%d --date="-132hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-84hour"` \
22 `date +%Y/%m/%d --date="-60hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-12hour"` \
23 )
24
25# time rawfile is untouched before further processing (i.e. adding checksum and zipping)
26delaytime=30 #30 minutes
27
28# setup to use ftools
29source $HEADAS/headas-init.sh
30
31# do rsync for rawfiles of these dates
32for date in ${dates[@]}
33do
34 echo "" >> $logfile 2>&1
35 rawdir=/loc_data/raw/$date
36 echo `date`": processing files in "$rawdir >> $logfile 2>&1
37 printprocesslog "INFO processing files in "$rawdir
38 #echo "INFO processing files in "$rawdir
39 # check if data are available from that night
40 if ! [ -d $rawdir ]
41 then
42 echo `date`": no data available in "$rawdir >> $logfile 2>&1
43 printprocesslog "INFO no data available in "$rawdir
44 continue
45 fi
46 zipdir=/loc_data/zipraw/$date
47 if ! [ -d $zipdir ]
48 then
49 # create output directory for zip
50 makedir $zipdir >> $logfile 2>&1
51 fi
52
53 # find all fits-files starting with the oldest file
54 echo `date`": finding files to be zipped in $rawdir..." >> $logfile 2>&1
55 printprocesslog "INFO finding files to be zipped in "$rawdir"..."
56 fitsfiles=`find $rawdir -type f -name '*fits'| sort `
57
58 if [ ${#fitsfiles[@]} -eq 0 ]
59 then
60 echo `date`": no files to be zipped in $rawdir..." >> $logfile 2>&1
61 printprocesslog "INFO no files to be zipped in "$rawdir"..."
62 continue
63 fi
64
65 # loop to zip files
66 echo `date`": zipping files in $rawdir..." >> $logfile 2>&1
67 printprocesslog "INFO zipping files in "$rawdir"..."
68 for file in $fitsfiles
69 do
70 # filename for temporary and final zipfile
71 zipfile=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
72 zipfiletmp=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
73 # check if zipped file already exists
74 if [ -e $zipfile ]
75 then
76 continue
77 fi
78
79 # check if raw file was accessed in the last $delaytime minutes
80 isnew=`find $file -amin -$delaytime`
81 if [ "$isnew" != "" ]
82 then
83 echo $file" is not older than $delaytime min => continue" >> $logfile 2>&1
84 printprocesslog "INFO "$file" is not older than $delaytime min => continue"
85 continue
86 fi
87
88 # check if file is already finished
89 # original file on daq (if data was taken on daq
90 origfile=`echo $file | sed -e 's/loc_data/daq/'`
91 if [ -e $origfile ]
92 then
93 # get time of last modification as seconds since Epoch for both files
94 timeorig=`stat -c %Y $origfile`
95 timecopy=`stat -c %Y $file`
96 # compare times
97 if ! [ $timeorig -eq $timecopy ]
98 then
99 # if times are not the same, the file is still open => no zip
100 echo `date`": file "$file" not yet closed => continue" >> $logfile 2>&1
101 printprocesslog "WARN file "$file" not yet closed => continue"
102 continue
103 fi
104 else
105 # if the origfile doesn't exist, the data was probably written not on daq but on data
106 echo `date`": file "$file" was probably taken on data and not daq " >> $logfile 2>&1
107 printprocesslog "WARN file "$file" was probably taken on data and not daq "
108 fi
109
110# # update the raw file with the checksums
111# ftchecksum update=yes $file >> $logfile 2>&1
112# check=$?
113# if [ $check -eq 0 ]
114# then
115# echo `date`": file "$file" was updated with the checksums " >> $logfile 2>&1
116# else
117# echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")" >> $logfile 2>&1
118# echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")"
119# continue
120# fi
121
122 echo `date`": zipping "$file" to "$zipfile" ..." >> $logfile 2>&1
123 printprocesslog "INFO zipping "$file" to "$zipfile" ..."
124 #echo "INFO zipping "$file" to "$zipfile" ..."
125 # zip file to stdout and pipe it to outputfile
126 if pigz -1 -c -f $file > $zipfiletmp
127 then
128 # if successful, move temporary to final zipfile
129 printprocesslog "INFO move "$zipfiletmp" to "$zipfile" ..."
130 mv -v $zipfiletmp $zipfile >> $logfile 2>&1
131 else
132 # if not successful, remove temporary zipfile
133 printprocesslog "INFO remove "$zipfiletmp"..."
134 rm -v $zipfiletmp >> $logfile 2>&1
135 fi
136 done
137done
138echo "finished zipping..." >> $logfile 2>&1
139finish
Note: See TracBrowser for help on using the repository browser.