#!/bin/sh date export PS4='$SECONDS ${0/\/nw.*\/nwps.*\/} + ' set -xa # #### 04/01/15 ############################### # SETUP NWPS SHELL VARIABLES # ############################################# export DATA=${DATA:-${DATAROOT}/${jobid}} mkdir $DATA cd $DATA curhour=$(date -u +%H) if [ $curhour -lt 12 ]; then CYCLE="00"; fi if [ $curhour -ge 12 ] && [ $curhour -lt 18 ]; then CYCLE="06"; fi if [ $curhour -ge 18 ] && [ $curhour -lt 22 ]; then CYCLE="12"; fi if [ $curhour -ge 22 ]; then CYCLE="18"; fi echo "" echo "INFO - Current hour is ${curhour}, setting model cycle to ${CYCLE}" export cyc=${CYCLE} export cycle=t${cyc}z #################################### # Specify NET and RUN Name and model #################################### export NET=${model} export RUN=$(echo ${job}|awk -F"_" '{print $2}') #################################### # SENDECF - Flag Events on ECFLOW # SENDCOM - Copy Files From TMPDIR to $COMOUT # SENDDBN - Issue DBNet Client Calls #################################### export SENDCOM=${SENDCOM:-YES} export SENDECF=${SENDECF:-YES} export SENDDBN=${SENDDBN:-YES} #################################### # Specify Execution Areas #################################### export HOMEnwps=${HOMEnwps:-${PACKAGEROOT}/${model}.${nwps_ver}} export FIXnwps=${FIXnwps:-${HOMEnwps}/fix} export EXECnwps=${EXECnwps:-${HOMEnwps}/exec} export SORCnwps=${SORCnwps:-${HOMEnwps}/sorc} export PARMnwps=${PARMnwps:-${HOMEnwps}/parm} export USHnwps=${USHnwps:-${HOMEnwps}/ush} export PMnwps=${PMnwps:-${USHnwps}/pm} export BATHYdb=${BATHYdb:-${FIXnwps}/bathy_db} export SHAPEFILEdb=${SHAPEFILEdb:-${FIXnwps}/shapefile_db} # Set NWPS run conditions export DEBUGGING=${DEBUGGING:-TRUE} export DEBUG_LEVEL=${DEBUG_LEVEL:-1} export ISPRODUCTION=${ISPRODUCTION:-TRUE} export SITETYPE=${SITETYPE:-EMC} export MODELTYPE="SWAN" # Maximum of wfos that can run at the same time export RUN_LIMIT=18 export pgmout=OUTPUT.$$ setpdy.sh . ./PDY ############################################## # Define COM directory ############################################## export GESOUT=${GESOUT:-$(compath.py -o ${NET}/${nwps_ver})/${NET}.${PDY}/nwges} export GESOUTm1=${GESOUTm1:-$(compath.py -o ${NET}/${nwps_ver})/${NET}.${PDYm1}/nwges} export dcom_hist="$GESOUT/dcom_hist.txt" export dcom_histm1="$GESOUTm1/dcom_hist.txt" export web_status_file="$GESOUT/status_file.txt" export dcom=${dcom:-${DCOMROOT}} export FORECASTWINDdir="${dcom}/${PDY}/wgrbbul/${NET}" # Establish rsync timeout and retry limits export RSYNC_MAX_SECONDS=${RSYNC_MAX_SECONDS:-100} export RSYNC_MAX_ATTEMPTS=${RSYNC_MAX_ATTEMPTS:-3} # make sure NWPS COM directory exists if [ "${SENDCOM}" = YES ]; then mkdir -p $GESOUT $GESOUT/warnings fi ############################################## # Execute the script ${HOMEnwps}/scripts/exnwps_datachk.sh export err=$?; err_chk #if [ $(hostname |cut -c1) = 'c' ]; then # export machine=cactus #else # export machine=dogwood #fi function rsync_sh { #source=$(echo ${@: -2}|awk '{print $1}') #dest=${@: -1} source=$1 dest=$2 set +xa echo ${options:?" FATAL ERROR: Need to set \"options\" properly to avoid lengthy transfers. "} if [ $# -eq 2 ] ; then echo "==========================================================================================" echo "Now running \"rsync $source $dest\" " echo "Please export $options before running this script." echo "==========================================================================================" echo " " else echo "FATAL ERROR: Not enough options given. Missing source or destination variable." echo "Usage: rsync_sh $source $dest" echo "Example: rsync_sh ${web_status_file} ${remote_stat}" echo "Define the variable options first" echo "export options=\"\-\-delete\"" fi set -xa let numattempts=$RSYNC_MAX_ATTEMPTS 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. Please requeue the failed job for the next datacheck!!" err_exit fi } #if [ "${envir}" = "prod" -a "$(cat /etc/prod)" = "${machine}" ]; then if [ "${envir}" = prod -a "${PARATEST}" != "YES" ]; then export remote_stat="nwprod@ncorzdm.ncep.noaa.gov:~/pmb/spa/nwps/status_file.txt" export remote_warn="nwprod@ncorzdm.ncep.noaa.gov:~/pmb/spa/nwps/warnings/" export options=(-aWzv --timeout=${RSYNC_MAX_SECONDS} --delete) else export remote_stat="nwprod@intra.ncep.noaa.gov:~/pmb/spatools/nwps_status/status_file.txt" export remote_warn="nwprod@intra.ncep.noaa.gov:~/pmb/spatools/nwps_status/warnings/" export options=(-aWzv --timeout=${RSYNC_MAX_SECONDS} --delete) fi if [ "${SENDWEB}" = "YES" ]; then rsync_sh ${web_status_file} ${remote_stat} rsync_sh ${GESOUT}/warnings/ ${remote_warn} fi ############################################## msg="JOB $job HAS COMPLETED NORMALLY." postmsg $jlogfile "$msg" if [ -e $pgmout ]; then cat $pgmout fi cd $DATAROOT if [ "$KEEPDATA" != YES ]; then rm -rf $DATA fi date