################################################################## #! /bin/csh -f # # Filename: SRS_customer_count.csh # # This Rev: 1.0 14-Feb-1997 # # Purpose: Updates Habitat customer counts from SRS host. # # Implementation: This script performs the following sequences: # # 1) Using ftp and the local .netrc file, attempts # $RETRY times within $RETRY * $SNOOZE seconds, # to log into $SRS_HOST and get $SRS_FILE. This # should contain the raw SRS customer count data. # 2) $SRS_FILE is copied to $HAB_HOST::$HAB_DIR$HAB_FILE. # using dcp. The same timeout used in 1) is applied. # The raw SRS data file is re-named during the dcp # copy in order to minimize the number of '.'s in # the filename for OpenVMS. # 3) A rsh session is started on $HAB_HOST in order # to start $HAB_SCR. $HAB_SCR is intend to launch # the VMS process, "MAKE_SRS_DAT.EXE" passing $HAB_FILE # as an argument. $HAB_SCR builds SUBSTATIONS names # from $HAB_FILE and maps the Habitat scadamom database. # $HAB_SCR searches the Habitat database for a matching # substation name. If one is found in Habitat, the # line from $HAB_FILE is included in the $HAB_SCR output # (currently text file SRS.DAT), else the entry is omitted. # 4) The output from $HAB_SCR along with a LOG file, is copied # from $HAB_HOST using dcp. This output is currently named # 'SRS.DAT' and 'SRS.LOG' and is defined in 'make_srs_dat.exe'. # 5) A sql routine is extracted from dms_merge on the Ingres # server in order to create an Ingres table from SRS.DAT. # 6) The Ingres REPORT WRITER utility is invoked using the # Ingres table created in 5) in order to format a report that # contains commands suitable for input into Habitat's PTB # facility. The PTB scripts are copied to $HAB_HOST using dcp. # 7) Finally, a rsh session is started on $HAB_HOST in order to # start PTB using the PTB scripts created above. This step # updates the Habitat database from the SRS customer counts. # # History: # # v1.0 - J. Martin, Puget Sound Power Co. NOW Puget Sound Energy. # ################################################################## set VER = 'v1.0' #version of this script set STAMP = `date` #now date/time stamp set CMD = `basename $0` #name immune from change set LOG = 'srs.log' #log file name set SRS_HOST = 'merlin' #SRS host set HAB_HOST = 'tiger2' #primary HAB host set HAB_DIR = 'pan90' #dir where HAB_SCR is set HAB_SCR = '@RUN_MAKE_SRS_DAT.COM' #HAB script filename set SRS_FILE = "'PO0.SRS.TREECKTT.FILE'" #SRS file name set HAB_FILE = 'TREECKTT.FILE' #file in HAB_DIR to copy to set RETRY = 3 #number of re-tries set CUR_TRY #current ftp attempt set SNOOZE = 60 #number secs between re-tries set DCP_FAILED = 1 #cleared if dcp copy successful set COUNT #gen. duty integer var. # #annouce ourselves.. # echo " " >>$LOG echo "***********************************************************" >>$LOG echo "$STAMP" >>$LOG echo "$CMD $VER started on `hostname` " >>$LOG echo "***********************************************************" >>$LOG echo " " >>$LOG echo " " echo "***********************************************************" echo "$STAMP" echo "$CMD $VER started on `hostname` " echo "***********************************************************" echo " " # # establish path for ingres objects # set path = ($II_SYSTEM/ingres/{bin,utility} $path) # # try to download raw SRS customer count file TREECKTT.FILE # from SRS_HOST using ftp. (assumes local .netrc handles login # info). Removing ftp.log first ensures that any previous ftp's # won't confuse this script. # if( -e SRS_ftp.log) then rm SRS_ftp.log endif @ COUNT = $RETRY while( $RETRY > 0 ) ftp -v $SRS_HOST << endftp > SRS_ftp.log get $SRS_FILE quit endftp # we'll accept any data as ftp success... fgrep 'bytes received' SRS_ftp.log >> /dev/null if( $status != 0 ) then @ RETRY = $RETRY - 1 @ CUR_TRY = $COUNT - $RETRY echo "ftp from $SRS_HOST retry $CUR_TRY of $COUNT failed." echo "re-try in $SNOOZE seconds..." sleep $SNOOZE else @ RETRY = 0 endif end # end ftp RETRY while fgrep 'bytes received' SRS_ftp.log if( $status != 0 ) then echo ' ' echo '******************************************************' >>$LOG echo "$STAMP" >>$LOG echo "From: $CMD on `hostname` " >>$LOG echo "gave up on ftp from $SRS_HOST " >>$LOG echo "after $COUNT failures within $SNOOZE minutes." >>$LOG echo '******************************************************' >>$LOG echo ' ' # # give an error on stdout as well... # echo ' ' echo '******************************************************' echo "$STAMP" echo "From: $CMD on `hostname` " echo "gave up on ftp from $SRS_HOST " echo "after $COUNT failures within $SNOOZE minutes." echo '******************************************************' echo ' ' # # exit with an error status # exit 1 # # ftp assumed successful within timeout period, continue.. # else # # copy the raw file over to HAB_HOST # @ RETRY = $COUNT while( $RETRY > 0 ) dcp -v $SRS_FILE $HAB_HOST/$HAB_DIR/bay2zom::$HAB_FILE if( $status != 0 ) then @ RETRY = $RETRY - 1 @ CUR_TRY = $COUNT - $RETRY echo "dcp to $HAB_HOST retry $CUR_TRY of $COUNT failed." echo "re-try in $SNOOZE seconds..." sleep $SNOOZE else @ RETRY = 0 @ DCP_FAILED = 0 endif end #end dcp RETRY while if( $DCP_FAILED != 0 ) then echo ' ' echo '******************************************************' >>$LOG echo "$STAMP" >>$LOG echo "From: $CMD on `hostname` " >>$LOG echo "gave up on dcp to $HAB_HOST " >>$LOG echo "after $COUNT failures within $SNOOZE minutes." >>$LOG echo '******************************************************' >>$LOG echo ' ' # # give an error on stdout as well... # echo ' ' echo '******************************************************' echo "$STAMP" echo "From: $CMD on `hostname` " echo "gave up on dcp to $HAB_HOST " echo "after $COUNT failures within $SNOOZE minutes." echo '******************************************************' echo ' ' # # exit with an error status # exit 1 # # dcp successful, continue... # else # # start rsh to HAB_HOST in order to run HAB_SCR there... # if( -e srs.dat ) then rm srs.dat endif rsh $HAB_HOST -l $HAB_DIR $HAB_SCR $HAB_FILE if( $status != 0 ) then echo ' ' echo '******************************************************' >>$LOG echo "$STAMP" >>$LOG echo "From: $CMD on `hostname` " >>$LOG echo "gave up on rsh $HAB_SCR on $HAB_HOST " >>$LOG echo '******************************************************' >>$LOG echo ' ' # # give an error on stdout as well... # echo ' ' echo '******************************************************' echo "$STAMP" echo "From: $CMD on `hostname` " echo "gave up on rsh $HAB_SCR on $HAB_HOST " echo '******************************************************' echo ' ' # # exit with error status # exit -1 endif # # copy the processed HAB_FILE and log from HAB_HOST # dcp -v $HAB_HOST/$HAB_DIR/bay2zom::SRS.DAT srs.dat dcp -v $HAB_HOST/$HAB_DIR/bay2zom::SRS.LOG SRS.LOG if( $status != 0 ) then echo ' ' echo '******************************************************' >>$LOG echo "$STAMP" >>$LOG echo "From: $CMD on `hostname` " >>$LOG echo "gave up on dcp copy of SRS files from $HAB_HOST " >>$LOG echo '******************************************************' >>$LOG echo ' ' # # give an error on stdout as well... # echo ' ' echo '******************************************************' echo "$STAMP" echo "From: $CMD on `hostname` " echo "gave up on dcp copy of SRS files from $HAB_HOST " echo '******************************************************' echo ' ' # # exit with error status # exit -1 endif # # read srs data into Ingres data (srs_data table # sql dms_merge < SRS_customer_count.sql >> $LOG if( $status != 0 ) then echo ' ' echo '******************************************************' >>$LOG echo "$STAMP" >>$LOG echo "From: $CMD on `hostname` " >>$LOG echo "gave up on SRS_customer_count.sql" >>$LOG echo '******************************************************' >>$LOG echo ' ' # # give an error on stdout as well... # echo ' ' echo '******************************************************' echo "$STAMP" echo "From: $CMD on `hostname` " echo "gave up on SRS_customer_count.sql" echo '******************************************************' echo ' ' # # exit with error status # exit -1 endif # # create PTB scripts with report writer # sreport dms_merge SRS_custcnt.rw sreport dms_merge SRS_subcnt.rw report -fckt_count.ptb dms_merge srs_custcnt report -fsub_count.ptb dms_merge srs_subcnt if( $status != 0 ) then echo ' ' echo '******************************************************' >>$LOG echo "$STAMP" >>$LOG echo "From: $CMD on `hostname` " >>$LOG echo "gave up on building PTB scripts using report writer" >>$LOG echo '******************************************************' >>$LOG echo ' ' # # give an error on stdout as well... # echo ' ' echo '******************************************************' echo "$STAMP" echo "From: $CMD on `hostname` " echo "gave up on building PTB scripts using report writer" echo '******************************************************' echo ' ' # # exit with error status # exit -1 endif # # move PTB scripts to Habitat servers # dcp -v *.ptb $HAB_HOST/$HAB_DIR/bay2zom:: # # make sure new ptb scripts copied ok # if( $status != 0 ) then echo ' ' echo '******************************************************' >>$LOG echo "$STAMP" >>$LOG echo "From: $CMD on `hostname` " >>$LOG echo "gave up on dcp copy of PTB scripts to $HAB_HOST " >>$LOG echo '******************************************************' >>$LOG echo ' ' # # give an error on stdout as well... # echo ' ' echo '******************************************************' echo "$STAMP" echo "From: $CMD on `hostname` " echo "gave up on dcp copy of PTB scripts to $HAB_HOST " echo '******************************************************' echo ' ' # # exit with error status # exit -1 endif # # start PTB to implement the new customer counts in Habitat # rsh $HAB_HOST -l $HAB_DIR '@srs_ptb.com' >> $LOG if( $status != 0 ) then echo ' ' echo '******************************************************' >>$LOG echo "$STAMP" >>$LOG echo "From: $CMD on `hostname` " >>$LOG echo "gave up on rsh to $HAB_HOST to run PTB" >>$LOG echo '******************************************************' >>$LOG echo ' ' # # give an error on stdout as well... # echo ' ' echo '******************************************************' echo "$STAMP" echo "From: $CMD on `hostname` " echo "gave up on rsh to $HAB_HOST to run PTB" echo '******************************************************' echo ' ' # # exit with error status # exit -1 endif exit 0