#!/usr/bin/ksh # # gbo_step_atha_mirror.ksh - Using rsync,to mirror the STEP Polar # Ground Magnetometer (GMAG) files from University of Athabasca. # # Usage: gbo_step_atha_mirror.ksh [year] [month] [day] # # Arguments: # $1 = site # $2 = year # $3 = month # $4 = day # # # Based heavily on gbo_atha_rmd_mirror.ksh by Tim Quinn # # # ## Set the environment variables # if [[ -z $THMSOC ]] then THMSOC=/disks/socware/thmsoc_dp_current export THMSOC fi . ${THMSOC}/src/config/soc_it_to_me.config . ${THMSOC}/src/config/gbo_step_atha_mirror.config # Take input arguments and build mirror directories # site=$1 year=$2 month=$3 day=$4 args_dir_path=${year}/${month}/${day}/ if [[ -z $month && -z $day ]] then args_dir_path=${args_dir_path%%//} elif [[ -z $day ]] then args_dir_path=${args_dir_path%/} fi mirror_start_dir="$STEP_MIRROR_HOME/$site/${args_dir_path}" mkdir -p $mirror_start_dir cd $mirror_start_dir ## Run rsync # echo "$$:" >> $LOGFILE echo "$$:----------- Starting gbo_step_atha_mirror at $(date) ---------" >> $LOGFILE start_time=$(date -u '+%Y-%m-%d %T') filenum=0 RSYNC_LOGFILE=${RSLOGFILE}_pid$$_${filenum} if [[ -n $5 ]] then count=$5 while (( $count > 0 )) do echo "Starting rsync at directory level ${args_dir_path}" >> $LOGFILE echo "Starting rsync at directory level ${args_dir_path}" >> $RSYNC_LOGFILE echo "Rsync Options Used: $RSYNC_OPTIONS" >> $RSYNC_LOGFILE echo "Rsync Path Requested: ${REMOTE_SERVER_NAME}/${site}/fluxgate/${args_dir_path}" >> $RSYNC_LOGFILE # Run rsync /usr/bin/rsync $RSYNC_OPTIONS --include="*.txt" --rsh="ssh -l themis" ${REMOTE_SERVER_NAME}/${site}/fluxgate/${args_dir_path} . >> $RSYNC_LOGFILE # Now increment date dateseconds=$(date --date "${year}-${month}-${day}" +%s) nextseconds=$(($dateseconds+60*60*24)) nextday=$(date --date "1970-01-01 ${nextseconds} sec GMT" +%Y/%m/%d) #deltadate doesn't work anymore # nextday=$(/usr/bin/ssh juneau /disks/juneau/home/teq/ws/src/fastlib/deltaDate \ # ${month}/${day}/${year} 1) month=$(echo $nextday |awk -F/ '{ printf("%02s",$2) }') day=$(echo $nextday |awk -F/ '{ printf("%02s",$3) }') year=$(echo $nextday |awk -F/ '{ printf("%s",$1) }') args_dir_path=$(echo $nextday |awk -F/ '{ printf("%s/%02s/%02s/",$1,$2,$3) }') args_dir_path=${school}/${args_dir_path} mirror_start_dir="$STEP_MIRROR_HOME/${args_dir_path}" mkdir -p $mirror_start_dir cd $mirror_start_dir count=$(( $count - 1 )) filenum=$(( $filenum + 1 )) RSYNC_LOGFILE=${RSLOGFILE}_pid$$_${filenum} done else echo "Starting rsync at directory level ${args_dir_path}" >> $LOGFILE echo "Starting rsync at directory level ${args_dir_path}" >> $RSYNC_LOGFILE echo "Rsync Options Used: $RSYNC_OPTIONS" >> $RSYNC_LOGFILE echo "Rsync Path Requested: ${REMOTE_SERVER_NAME}/${site}/fluxgate/${args_dir_path}" >> $RSYNC_LOGFILE which rsync >> $LOGFILE # Run rsync /usr/bin/rsync $RSYNC_OPTIONS --include="*.txt" --rsh="ssh -l themis" ${REMOTE_SERVER_NAME}/${site}/fluxgate/${args_dir_path} . >> $RSYNC_LOGFILE rsynccode=$? if (( $rsynccode != 0 )) then echo "WARNING RSYNC PROBLEM: Return code = $rsynccode" >> $LOGFILE printf "%s\n" "script: $0" msg="Warning: STEP UAtha RSYNC Problem:code $rsynccode: path ${args_dir_path}" thmsoc_dblog.php $(basename $0) 2 "$msg" ### added 2012-06-25 - bsadeghi fi fi end_time=$(date -u '+%Y-%m-%d %T') ## Process log files created by rsync run. ## Check rsync results by seeing if any files were ## recovered or updated # logfilelist=$(ls -1 ${RSLOGFILE}_pid$$_*) for logfile in $logfilelist do egrep '(>f)' $logfile > /tmp/GBO_CHECK$$ while [[ -s /tmp/GBO_CHECK$$ ]] do line=$(head -1 /tmp/GBO_CHECK$$) processCode=$(echo $line |awk -F\| '{print substr($1,3,8)}') path=$(echo $line |awk -F\| '{print $2}') processTime=$(echo $line |awk -F\| '{print $3}' | sed 's/\//-/g') fileSize=$(echo $line |awk -F\| '{print $4}'| sed 's/"//g') fileName=${path##*/} schName=$(echo $fileName |awk -F_ '{print substr($1,1,4)}') year=$(echo $fileName | awk -F_ '{print "20"substr($1,5,2)}') month=$(echo $fileName | awk -F_ '{print substr($1,7,2)}') day=$(echo $fileName | awk -F_ '{print substr($1,9,2)}') hr=$(echo $fileName | awk -F_ '{print $3}') mn=$(echo $fileName | awk -F_ '{print substr($4,1,2)}') dataTime="${year}-${month}-${day} ${hr}:${mn}:00" mysql_table_name=gbo_${schName}_files echo "$$: Updating MySQL database table $mysql_table_name......." >> $LOGFILE gbo_step_mirror.php $mysql_table_name $dataTime $fileName $processTime $processCode $fileSize >> $LOGFILE echo "$$: ...........update complete. " >> $LOGFILE sed '1d' /tmp/GBO_CHECK$$ > /tmp/gbo_check$$ mv /tmp/gbo_check$$ /tmp/GBO_CHECK$$ done rm /tmp/GBO_CHECK$$ # Process rsync statistics into database rsync_dir=$(grep rsync $logfile | awk '{print $6}') num_files=$(grep "Number of files transferred" $logfile | awk '{print $5}') tot_size=$(grep "Total file size" $logfile | awk '{print $4}') xfer_rate=$(grep "bytes/sec" $logfile | awk '{print $7}') # Now, create a file containing just the directories # that have had files updated by rsync. These directories # will be processed to convert the s to FFs # egrep '(>f)' $logfile | awk -F\| '{print $2}' > /tmp/STEP_Files$$ previous=NaN for line in $(cat /tmp/STEP_Files$$) do filename=$(basename $line) sub_filename=$(echo $filename |awk '{print substr($1,1,10)}') site=$(echo $sub_filename |awk '{print substr($1,1,4)}') if [[ $sub_filename != $previous ]] then if [[ $site != "PGEO" ]] then echo $sub_filename >> $GMAGMIRROR/STEPdirs$$ previous=${sub_filename} fi fi done rm /tmp/STEP_Files$$ done echo "$$:" >> $LOGFILE echo "$$:----------- Ending gbo_step_atha_mirror at $(date) ---------" >> $LOGFILE exit 0