#!/usr/bin/ksh # # lzprocess.ksh - This program processes probe VC files # into time-ordered, overlap deleted packet files covering # one 24 hour day. # # # Creation Date: # # 6 December 2006 TimQuinn # # Updates: # ## Set the environment variables # . $HOME/software_dev/config/new.lzprocess.config . $HOME/software_dev/config/soc_it_to_me.config ## Start LOG output # echo "$$:" >> $LOGFILE echo "$$:----------- Starting LZP Process at $(date) ---------" >> $LOGFILE ## Check for lock file # if [[ -a ${LOCKDIR}/${LOCKFILE} ]] then echo "$$:" >> $LOGFILE echo "$$: A lock file was found. Checking date......" >> $LOGFILE chkdate=$(find $LOCKDIR -name $LOCKFILE -mtime -1) if [[ -z $chkdate ]] then machine=$(uname -a | awk '{print $2}') echo "$$: WARNING: Lock file on $machine is older then 1 day." >> $LOGFILE echo "$$: Issuing warning and quitting.." >> $LOGFILE printf "%s\n" "script: $0" \ "Warning: Lock file on $machine is older then 1 day " | mailx -s "THEMIS Processing Problem - LZ Lock File" $SOC_EMAIL exit 1 fi echo "$$: Quittin..................." >> $LOGFILE exit 0 fi echo $$ > ${LOCKDIR}/${LOCKFILE} ## Process the VC3 files in the target directory # for vcfile in $(ls -1 ${VCDROP}/*THEMIS* 2>/dev/null) do ## If VC file is not zero length, start processing # if [[ -s $vcfile ]] then echo "$$:" >> $LOGFILE echo "$$: VC file $nameonly found. Processing......." >> $LOGFILE ## Grab some information from the filename for later use # nameonly=$(basename $vcfile) rootFilename=$(basename ${vcfile%.*}) noextension=$(echo $nameonly |awk -F. '{print $1"."$2"."$3"."$4}') probeID=$(echo $nameonly |awk -F. '{print $2}') vcprobeid="th$(echo $probeID | awk -F_ '{print tolower($2)}')" year=$(echo $nameonly |awk -F. '{print substr($4,1,4)}') doy=$(echo $nameonly |awk -F. '{print substr($4,6,3)}') startTime=$(date -u '+%Y-%m-%d %T') echo "$$:" >> $LOGFILE echo "$$: Initiationing LZ process at $(date):" >> $LOGFILE echo "$$: $THMBIN/test_prog_smex $nameonly............." >> $LOGFILE cd ${SCRATCH}/lzprocess $THMBIN/test_prog_smex $vcfile 1> $LOGDIR/${noextension}.log 2>&1 echo "$$:" >> $LOGFILE echo "$$: .....LZ process complete at $(date)." >> $LOGFILE stopTime=$(date -u '+%Y-%m-%d %T') ## Place VC processing information in database. The execution of ## this command returns the line number which will be associated ## with each L1 file created. # echo "$$:" >> $LOGFILE echo "$$: Updating database:" >> $LOGFILE echo "$$: vc.php $nameonly $startTime $stopTime" >> $LOGFILE vcfileid=$(/home/thmsoc/software_dev/php/vc.php $nameonly $startTime $stopTime) ## Update database with information on each file # grep FileResults $LOGDIR/${noextension}.log > /tmp/${noextension}.log if [[ -s /tmp/${noextension}.log ]] then while read line do ## Parse out information on each file # fileName=$(echo $line |awk -F\| '{print $2}') calcSize=$(echo $line |awk -F\| '{print $3}') measSize=$(echo $line |awk -F\| '{print $4}') scId=$(echo $line |awk -F\| '{print $5}') pktId=$(echo $line |awk -F\| '{print $6}') pktCnt=$(echo $line |awk -F\| '{print $7}') rawStartTime=$(echo $line |awk -F\| '{print $8}') rawStopTime=$(echo $line |awk -F\| '{print $9}') ## Insert line into DB # echo "$$:" >> $LOGFILE echo "$$: Updating database:" >> $LOGFILE echo "$$: lzp.php $vcfileid $fileName $calcSize $measSize $scId $pktId $pktCnt $rawStartTime $rawStopTime " >> $LOGFILE /home/thmsoc/software_dev/php/lzp.php $vcfileid $fileName $calcSize $measSize $scId $pktId $pktCnt $rawStartTime $rawStopTime ## Check for file size discrepancies # if (( $calcSize != $measSize )) then echo "$$:" >> $LOGFILE echo "$$:WARNING: File Size Discrepancy: calcSize = $calcSize" >> $LOGFILE printf "%s\n" "script: $0" \ "Warning: File Size Discrepancy for $fileName: calcSize = $calcSize" | mailx -s "THEMIS LZ Processing Problem - File Size Discrepancy" $SOC_EMAIL fi ## Deconstruct filename ## - filename = th[a-e]_L0_nnn_yyyymmdd.pkt # lzfileyear=$(echo $fileName |awk -F_ '{print substr($4,1,4)}') lzfilemonth=$(echo $fileName |awk -F_ '{print substr($4,5,2)}') lzfileday=$(echo $fileName |awk -F_ '{print substr($4,7,2)}') lzfilescid=$(echo $fileName |awk -F_ '{print $1}') lzfileapid=$(echo $fileName |awk -F_ '{print $3}') ## Check for erroneous time # currentYear=$(date '+%Y') lastYear=$(( $currentYear - 1 )) nextYear=$(( $currentYear + 1 )) if (( $lzfileyear < $lastYear || $lzfileyear > $nextYear )) then ## Possible time problem # echo "$$:" >> $LOGFILE echo "$$:Time Check Failure. File being moved to:" >> $LOGFILE echo "$$:$THEMISDATA/$lzfilescid/l0/PROBLEM_PKT/$lzfileyear/$rootFilename:" >> $LOGFILE mkdir -p $THEMISDATA/$lzfilescid/l0/PROBLEM_PKT/$lzfileyear/$rootFilename mv -f $fileName $THEMISDATA/$lzfilescid/l0/PROBLEM_PKT/$lzfileyear/$rootFilename else echo "$$:" >> $LOGFILE echo "$$: Making LZ archive directory:" >> $LOGFILE echo "$$: $THEMISDATA/$lzfilescid/l0/$lzfileyear/$lzfilemonth/$lzfileday" >> $LOGFILE mkdir -p $THEMISDATA/$lzfilescid/l0/$lzfileyear/$lzfilemonth/$lzfileday echo "$$:" >> $LOGFILE echo "$$: Moving LZ file $fileName to:" >> $LOGFILE echo "$$: $THEMISDATA/$lzfilescid/l0/$lzfileyear/$lzfilemonth/$lzfileday" >> $LOGFILE mv -f $fileName $THEMISDATA/$lzfilescid/l0/$lzfileyear/$lzfilemonth/$lzfileday echo $THEMISDATA/$lzfilescid/l0/$lzfileyear/$lzfilemonth/$lzfileday >> /tmp/thm_l0_filelist$$ fi done < /tmp/${noextension}.log else ## This L0 run produced no packet files # echo "$$:" >> $LOGFILE echo "$$:WARNING: VC file $vcfile produced no packet files" >> $LOGFILE printf "%s\n" "script: $0" \ "Warning: VC file $vcfile produced no packet files" | mailx -s "THEMIS LZ Processing Problem - No Pkt File Produced" $SOC_EMAIL fi else ## VC File is zero length. Alert Ops and delete file # echo "$$:" >> $LOGFILE echo "$$:WARNING: VC file $vcfile is zero length" >> $LOGFILE printf "%s\n" "script: $0" \ "Warning: VC file $vcfile is zero length" | mailx -s "THEMIS LZ Processing Problem - Zero Length File" $SOC_EMAIL fi ## Compare VC file probe ID to that derived from data ## then place in VC archive # if [[ $vcprobeid != $lzfilescid ]] then echo "$$:" >> $LOGFILE echo "$$: WARNING: VC File name discrepancy" >> $LOGFILE printf "%s\n" "script: $0" \ "Warning: VC file $nameonly has data for $lzfilescid" | mailx -s "THEMIS LZ Processing Problem - File Name Discrepancy" $SOC_EMAIL fi echo "$$:" >> $LOGFILE echo "$$: Moving VC file $nameonly to archive" >> $LOGFILE echo "$$: mkdir -p $THEMISDATA/$lzfilescid/vc_archive/$lzfileyear " >> $LOGFILE echo "$$: mv -f $vcfile $THEMISDATA/$lzfilescid/vc_archive/$lzfileyear " >> $LOGFILE mkdir -p $THEMISDATA/$lzfilescid/vc_archive/$lzfileyear mv -f $vcfile $THEMISDATA/$lzfilescid/vc_archive/$lzfileyear done echo "$$:----------- Ending LZ Process at $(date) ---------" >> $LOGFILE rm ${LOCKDIR}/${LOCKFILE} exit 0