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