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 |
|
---|
6 | source `dirname $0`/../Sourcefile.sh
|
---|
7 | printprocesslog "INFO starting "$0
|
---|
8 |
|
---|
9 | logfile=$runlogpath"/ZipRawLP-"$datetime".log"
|
---|
10 | date >> $logfile
|
---|
11 |
|
---|
12 | if ! ls /daq/raw >/dev/null 2>&1
|
---|
13 | then
|
---|
14 | printprocesslog "ERROR /daq/raw is not available."
|
---|
15 | finish
|
---|
16 | fi
|
---|
17 | # if daq unavailable
|
---|
18 | #if ! ls /newdaq/raw >/dev/null 2>&1
|
---|
19 | #then
|
---|
20 | # printprocesslog "ERROR /newdaq/raw is not available."
|
---|
21 | # finish
|
---|
22 | #fi
|
---|
23 |
|
---|
24 | # get dates
|
---|
25 | if [ "$certaindate" != "" ]
|
---|
26 | then
|
---|
27 | getdates $certaindate
|
---|
28 | else
|
---|
29 | # get all night
|
---|
30 | #getdates "all"
|
---|
31 | # get last 3 nights if hour between 7 and 19h, else only current night
|
---|
32 | getdates 3 7 19
|
---|
33 | fi
|
---|
34 |
|
---|
35 | # not needed anymore as ftools are not used anymore
|
---|
36 | ## setup to use ftools
|
---|
37 | #source $HEADAS/headas-init.sh
|
---|
38 |
|
---|
39 | # files younger than $delaytime are not processed
|
---|
40 | delaytime=5
|
---|
41 |
|
---|
42 | # do rsync for rawfiles of these dates
|
---|
43 | for date in ${dates[@]}
|
---|
44 | do
|
---|
45 | echo "" >> $logfile 2>&1
|
---|
46 | rawdir=/daq/raw/$date
|
---|
47 | # rawdir=/newdaq/raw/$date #if daq unavailable
|
---|
48 | echo `date`": processing files in "$rawdir >> $logfile 2>&1
|
---|
49 | printprocesslog "INFO processing files in "$rawdir
|
---|
50 | #echo "INFO processing files in "$rawdir
|
---|
51 | # check if data are available from that night
|
---|
52 | if ! [ -d $rawdir ]
|
---|
53 | then
|
---|
54 | echo `date`": no data available in "$rawdir >> $logfile 2>&1
|
---|
55 | printprocesslog "INFO no data available in "$rawdir
|
---|
56 | continue
|
---|
57 | fi
|
---|
58 |
|
---|
59 | # find all fits-files starting with the oldest file
|
---|
60 | echo `date`": finding files to be zipped in $rawdir..." >> $logfile 2>&1
|
---|
61 | printprocesslog "INFO finding files to be zipped in "$rawdir"..."
|
---|
62 | fitsfiles=`find $rawdir -type f -regex '.*[.]fits[.]?[g]?[f]?[z]?' | sort `
|
---|
63 |
|
---|
64 | if [ ${#fitsfiles[@]} -eq 0 ]
|
---|
65 | then
|
---|
66 | echo `date`": no files to be zipped in $rawdir..." >> $logfile 2>&1
|
---|
67 | printprocesslog "INFO no files to be zipped in "$rawdir"..."
|
---|
68 | continue
|
---|
69 | fi
|
---|
70 |
|
---|
71 | zipdir=/loc_data/zipraw/$date
|
---|
72 | # create output directory for zip
|
---|
73 | makedir $zipdir >> $logfile 2>&1
|
---|
74 |
|
---|
75 | # loop to zip files
|
---|
76 | echo `date`": zipping files in $rawdir..." >> $logfile 2>&1
|
---|
77 | printprocesslog "INFO zipping files in "$rawdir"..."
|
---|
78 | for file in $fitsfiles
|
---|
79 | do
|
---|
80 | # check if more than ~ 10 GB are left on /loc_data
|
---|
81 | diskusage=( `df -P /loc_data | grep /loc_data ` )
|
---|
82 | if [ ${diskusage[3]} -lt 10000000 ]
|
---|
83 | then
|
---|
84 | echo "WARN less than 10 GB left on /loc_data on data ("${diskusage[3]}")" >> $logfile 2>&1
|
---|
85 | printprocesslog "WARN less than 10 GB left on /loc_data on data ("${diskusage[3]}")"
|
---|
86 | finish
|
---|
87 | fi
|
---|
88 |
|
---|
89 | # check if raw file was accessed in the last $delaytime minutes
|
---|
90 | isnew=`find $file -amin -$delaytime`
|
---|
91 | if [ "$isnew" != "" ]
|
---|
92 | then
|
---|
93 | echo $file" is not older than $delaytime min => continue" >> $logfile 2>&1
|
---|
94 | printprocesslog "INFO "$file" is not older than $delaytime min => continue"
|
---|
95 | continue
|
---|
96 | fi
|
---|
97 |
|
---|
98 | iszipped=`echo $file | grep -o fz`
|
---|
99 | if [ "$iszipped" == "fz" ]
|
---|
100 | then
|
---|
101 | # treat already compressed files
|
---|
102 | printprocesslog "DEBUG treat compressed file "$file
|
---|
103 |
|
---|
104 | # filename for file on data
|
---|
105 | zipfile=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' `
|
---|
106 | zipfiletmp=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits.fz/fits.fz.tmp/'`
|
---|
107 | # # if daq unavailable
|
---|
108 | # zipfile=`echo $file | sed -e 's/newdaq/loc_data/g' -e 's/raw/zipraw/' `
|
---|
109 | # zipfiletmp=`echo $file | sed -e 's/newdaq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits.fz/fits.fz.tmp/'`
|
---|
110 |
|
---|
111 | # check if file on data already exists
|
---|
112 | if [ -e $zipfile ]
|
---|
113 | then
|
---|
114 | continue
|
---|
115 | fi
|
---|
116 |
|
---|
117 | echo `date`": copying "$file" to "$zipfile" ..." >> $logfile 2>&1
|
---|
118 | printprocesslog "INFO copying "$file" to "$zipfile" ..."
|
---|
119 | #echo "INFO zipping "$file" to "$zipfile" ..."
|
---|
120 | # read setup again to allow for updates of variables defining transfer
|
---|
121 | source `dirname $0`/../Sourcefile.sh
|
---|
122 | # zip file to stdout and pipe it to outputfile
|
---|
123 | echo "pv --rate-limit $limitpigz $file > $zipfiletmp" >> $logfile 2>&1
|
---|
124 | pv --rate-limit $limitpigz $file > $zipfiletmp
|
---|
125 | statuspv=$?
|
---|
126 | printprocesslog "DEBUG pvstatus:"$statuspv
|
---|
127 | echo " pvstatus:"$statuspv >> $logfile 2>&1
|
---|
128 | if [ $statuspv -eq 0 ]
|
---|
129 | then
|
---|
130 | # if successful, move temporary to final zipfile
|
---|
131 | printprocesslog "INFO move "$zipfiletmp" to "$zipfile" ..."
|
---|
132 | mv -v $zipfiletmp $zipfile >> $logfile 2>&1
|
---|
133 | else
|
---|
134 | # if not successful, remove temporary zipfile
|
---|
135 | printprocesslog "WARN pv failed (statuspv:"$statuspv")."
|
---|
136 | echo "WARN pv failed (PIPESTATUS:"$statuspv")." >> $logfile 2>&1
|
---|
137 | printprocesslog "INFO remove "$zipfiletmp"..."
|
---|
138 | rm -v $zipfiletmp >> $logfile 2>&1
|
---|
139 | finish
|
---|
140 | fi
|
---|
141 | else
|
---|
142 | # treat uncompressed files
|
---|
143 | printprocesslog "DEBUG treat uncompressed file "$file
|
---|
144 |
|
---|
145 | # filename for temporary and final zipfile
|
---|
146 | zipfile=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
|
---|
147 | zipfiletmp=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
|
---|
148 | # # if daq unavailable
|
---|
149 | # zipfile=`echo $file | sed -e 's/newdaq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
|
---|
150 | # zipfiletmp=`echo $file | sed -e 's/newdaq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
|
---|
151 |
|
---|
152 | # check if zipped file already exists
|
---|
153 | if [ -e $zipfile ]
|
---|
154 | then
|
---|
155 | continue
|
---|
156 | fi
|
---|
157 |
|
---|
158 | echo `date`": zipping "$file" to "$zipfile" ..." >> $logfile 2>&1
|
---|
159 | printprocesslog "INFO zipping "$file" to "$zipfile" ..."
|
---|
160 | #echo "INFO zipping "$file" to "$zipfile" ..."
|
---|
161 | # read setup again to allow for updates of variables defining transfer
|
---|
162 | source `dirname $0`/../Sourcefile.sh
|
---|
163 | # zip file to stdout and pipe it to outputfile
|
---|
164 | echo "pv --rate-limit $limitpigz $file | pigz -1 -c -f -p $numprocpigz > $zipfiletmp" >> $logfile 2>&1
|
---|
165 | pv --rate-limit $limitpigz $file | pigz -1 -c -f -p $numprocpigz > $zipfiletmp
|
---|
166 | statuspigz=( `echo ${PIPESTATUS[@]}` )
|
---|
167 | printprocesslog "DEBUG PIPESTATUS:"${statuspigz[@]}
|
---|
168 | echo " PIPESTATUS:"${statuspigz[@]} >> $logfile 2>&1
|
---|
169 | if [ ${statuspigz[0]} -eq 0 ] && [ ${statuspigz[1]} -eq 0 ]
|
---|
170 | then
|
---|
171 | # if successful, move temporary to final zipfile
|
---|
172 | printprocesslog "INFO move "$zipfiletmp" to "$zipfile" ..."
|
---|
173 | mv -v $zipfiletmp $zipfile >> $logfile 2>&1
|
---|
174 | else
|
---|
175 | # if not successful, remove temporary zipfile
|
---|
176 | printprocesslog "WARN pigz or pv failed (PIPESTATUS:"${statuspigz[@]}")."
|
---|
177 | echo "WARN pigz or pv failed (PIPESTATUS:"${statuspigz[@]}")." >> $logfile 2>&1
|
---|
178 | printprocesslog "INFO remove "$zipfiletmp"..."
|
---|
179 | rm -v $zipfiletmp >> $logfile 2>&1
|
---|
180 | finish
|
---|
181 | fi
|
---|
182 | fi
|
---|
183 | done
|
---|
184 | done
|
---|
185 | echo "finished zipping..." >> $logfile 2>&1
|
---|
186 | finish
|
---|