#!/bin/sh set -xa export PS4='$SECONDS + ' date -u ############################################## # Define DATE/TIME NET and RUN ############################################## export SENDWEB=${SENDWEB:-YES} export PDY=$(date +"%Y%m%d") export NET=hwm export RUN=hwm ############################################## # Define COMIN directory ############################################## export COMIN=${COMIN:-$(compath.py ${NET}/${hwm_ver}/${RUN}.${PDY})} function rsync_sh { source=$1 dest=$2 set +xa echo ${options:?" FATAL ERROR: Need to set \"options\" properly to avoid lengthy transfers. "} if [[ "${source}" == *"live_${res}_${rescount}_p1.json"* ]]; then echo "$source json live ${res} ${rescount} combined files found to transfer to intra!!!" elif [[ "${source}" == *"daily_${res}_${rescount}_p1.json"* ]]; then echo "$source json daily ${res} ${rescount} combined files found to transfer to intra!!!" else echo "FATAL ERROR: No json ${res} ${rescount} combined files found to transfer to intra!!!" err_exit fi if [ $# -eq 2 ] ; then echo "==========================================================================================" echo "Now running \"rsync $source $dest\" " echo "==========================================================================================" echo " " else echo "FATAL ERROR: Missing source or destination variable." echo "Usage: rsync_sh $source $dest" err_exit fi set -xa let numattempts=3 while [ $numattempts -gt 0 ]; do /usr/bin/rsync ${options[@]} ${source} ${dest} err=$? date if [ $err -eq 23 ] || [ $err -eq 24 ]; then echo "Possible Failure: error code is 23, check if any file is really missing" let numattempts=-1 # successful completion elif [ $err -ne 0 ]; then ((numattempts--)) sleep 5 else let numattempts=-1 # successful completion fi done if [ $numattempts -eq 0 ]; then echo "FATAL ERROR: rsync failed after three attempts" err_exit fi } export SERVER=nwprod@intra export RSYNC=rsync_sh export options=(-aWzv --timeout=30 --delete --progress --stats) cluster=$(cat /etc/cluster_name) if [[ "${cluster}" == "dogwood" ]] && [ "${envir}" = "prod" ]; then export REMOTE_DIR="~/pmb/spatools/HWM/DOGWOOD" elif [[ "${cluster}" == "cactus" ]] && [ "${envir}" = "prod" ]; then export REMOTE_DIR="~/pmb/spatools/HWM/CACTUS" fi if [[ "${cluster}" == "dogwood" ]] && [ "${envir}" = "para" ]; then export REMOTE_DIR="~/pmb/spatools/HWM/DOGWOOD_para" elif [[ "${cluster}" == "cactus" ]] && [ "${envir}" = "para" ]; then export REMOTE_DIR="~/pmb/spatools/HWM/CACTUS_para" fi if [ "${SENDWEB}" = "YES" ] && [ "${envir}" = "prod" ]; then echo "transfer live HWM files to intra!!!!" ${RSYNC} $COMIN/live_${res}_${rescount}_p1.json ${SERVER}:${REMOTE_DIR}/live/data export err=$?; err_chk echo "transfer daily HWM files to intra!!!!" ${RSYNC} $COMIN/daily_${res}_${rescount}_p1.json ${SERVER}:${REMOTE_DIR}/daily/data export err=$?; err_chk elif [ "${SENDWEB}" = "YES" ] && [ "${envir}" = "para" ];then echo "transfer live HWM files to intra!!!!" ${RSYNC} $COMIN/live_${res}_${rescount}_p1.json ${SERVER}:${REMOTE_DIR}/live/data export err=$?; err_chk echo "transfer daily HWM files to intra!!!!" ${RSYNC} $COMIN/daily_${res}_${rescount}_p1.json ${SERVER}:${REMOTE_DIR}/daily/data export err=$?; err_chk else echo "NO FILES BEING SENT TO INTRA WITH THIS RUN!!!!!!!!!!!!!" fi msg="JOB $job HAS COMPLETED NORMALLY." postmsg "$msg" date