#!/bin/ksh # - *************************************************************************** # - * Program reps2nt.ksh - by Daniel R. Martin (DRM/CTG) # - * Company Sprint Spectrum L.P. # - * Created Mon Oct 26 13:48:08 CST 1998 # - * Usage Launched from within Amdocs "exec_all_reports" script # - * Purpose FTP of MAF Reports to NT Server # - * ---------------------------------------------------------------- # - * Required supporting data files: # - * $BDRM/no_ftp - Contains the Partial Names of those MAF Reports # - * which are to be excluded from FTP. # SOMEONE MUST KEEP THIS EXCLUSION-LIST CURRENT !! # - * $HOME/.netrc - This file MUST be of mode 600. It MUST contain # the requisite entries for target NT system. e.g., # machine 208.10.99.51 login usmokcmmft01\\mafreports password report # - * ---------------------------------------------------------------- # - * NOTE: This script (reps2nt.ksh) does not use .netrc macros. # It expects to be run by the "mafuser" account. # - * ALERT: Parts of the ftp sections further below (near lines 233 & 300) # which issue the cd commands required to find the $NTRD Report # directory on $WAY will probably have to be changed for $PRD # - * LOOK: See "NOTE:" on $WAY selection at about line 43 below. # - * ------------------------------------------------------------------- # - * Change History # - * Date Who Description # - * 03/08/1999 DRM Imbued script with consciousness of value of MODE # - * variable set by Amdocs script exec_all_reports # - * which is done via invocation: reps2nt.ksh ${MODE} # - * The two possible MODE values are: DAILY MONTHLY # - * script then only needs to check the value of ${1} # - * to determine the correct actions to be taken. # - * 02/23/1999 DRM Enhanced to do separate FTP for Monthly Reports. # - * 02/12/1999 DRM Now can read from a file ($BDRM/no_ftp) containing # a list of Reports that are NOT to be FTPed. # - * 01/18/1999 DRM Replaced ls with "for" loop to avoid ls failure # - * 01/12/1999 DRM Changed $WAY for Production NT Server: # - * usmokcmkmft01 IP: 208.10.99.51 # - * ------------------------------------------------------------------- export EMOH="/apps/maf" # Directory under which bin_drm lives. export BDRM="${EMOH}/bin_drm" # Directory for required support file "no_ftp" FEX="${BDRM}/no_ftp" # Report Ftp-EXclusion List VER="70" # Version of MAF for which intended # Points ftp to the $WAY NT server (uncomment only one WAY below): # WAY="TST" # MAF Test NT Server on * TEST * Network WAY="PRD" # Production NT Server on PRODUCTION Network # NTRD variable must be set to a subdir under the default ftp login directory. # NOTE: IP and NTRD vars get set in the "case $WAY in" section further below. # The $WAY Server selected will require these three pre-conditions: # 1) Directories under $NTRD named "01" through "36" (empty ones are OK). # 2) Twelve Directories under $NTRD named "Jan" through "Dec" (empty are OK). # 3) A Directory under $NTRD named "zzz" to accept Unknown Reports. # Note: All directories required above will have to be created on $WAY. REM1="0_READ${VER}_A.txt" # Logfile of FTP Opening-Activity sent to $WAY. REM2="0_READ${VER}_B.txt" # Logfile of complete FTP Activity kept on UNIX. RDIR="/apps/cfd/reports" # Working Directory for MAF *.rep files. YAK="/tmp" # A good place (i.e., mode 777) to drop $REM[1|2]. DDIR="${YAK}/reps2ntD" # Directory into which Daily Reports are copied. MDIR="${YAK}/reps2ntM" # Directory into which Monthly Reports are copied. ########################## ## FUNCTION DEFINITIONS ## ########################## function _dang { # Required Arguments: $1 = Name of this Program # $2 = User-Abuse string cat << BOX | tee ${YAK}/$REM1 **-< ALERT >-** Program "$1" was terminated. $2 BOX date >>${YAK}/$REM1 exit 1 } # EOF _dang ############################## ## END FUNCTION DEFINITIONS ## ############################## [ -z "$WAY" ] && _dang "$0" "TARGET SERVER NETWORK (TST/PRD) IS NOT SET!" # Info on PRD case below is OK as of: Tue Jan 12 14:40:59 CST 1999 # - but it may need to be changed to reflect some future reality. case "$WAY" in TST) IP="207.40.73.254"; SV="uskmrssoa018" YK="MAF PT REPORTS" NTRD="D:/comm1/cdr_format_dist/reports/cfd_reports" ;; PRD) IP="208.10.99.51" ; SV="usmokcmmft01" YK="MAF PRODUCTION Report" NTRD="REPORTS" ;; *) IP='' ; NTRD="" ;; esac # Something like the line below goes in $HOME/.netrc # machine 208.10.99.51 login usmokcmmft01\\mafreports password report # Make sure all is well: [ -z "$IP" ] && _dang "$0" "NO TARGET SERVER IP ADDRESS SET!" [ -z "$NTRD" ] && _dang "$0" "NO TARGET NT SERVER REPORTS DIRECTORY SET!" [ -z "$1" ] && _dang "$0" "RUN-MODE (DAILY or MONTHLY) UNKNOWN!" [ -z "$YAK" ] && _dang "$0" "NO UNIX WORKING DIRECTORY SET!" [ ! -d "$YAK" ] && _dang "$0" "WORKING DIRECTORY \"$YAK\" DOES NOT EXIST!" [ ! -w "$YAK" ] && _dang "$0" "WORKING DIRECTORY \"$YAK\" IS NOT WRITEABLE!" [ -z "$RDIR" ] && _dang "$0" "DIRECTORY OF MAF SCHEDULED REPORTS NOT SET!" [ ! -s "$FEX" ] && _dang "$0" "EXCLUSION FILE (\"$FEX\") IS EMPTY OR MISSING!" [ ! -r "${HOME}/.netrc" ] && _dang "$0" "File \"${HOME}/.netrc\" missing!" # Make sure that run-mode augument is acceptable: case "$1" in DAILY) : ;; # OK to continue MONTHLY) : ;; # OK to continue *) _dang "$0" "RUN-MODE VALUE OF \"$1\" IS UNACCEPTABLE!" esac >${YAK}/${REM2} # Get a list of all MAF Scheduled Reports: for it in ${RDIR}/*.rep do echo ${it} >>${YAK}/${REM2} done ymd=`date '+%Y%m%d'` # "today" as YYYYMMDD (for example: 19991231) # Skim off just the MAF Reports for "today" ($ymd) (may include Monthly) # - and also exclude any Report names listed within the $FEX file. while read ugly do echo `basename $ugly` done <${YAK}/$REM2 | awk -v tdy="$ymd" -v nof="$FEX" ' BEGIN \ { bf = 1 # First element of array bfi[] idx = 0 # If (idx > 0) then that Report must be excluded. # nof = # Value of $FEX pathname passed in from the shell (via -v above) # tdy = # Value of $ymd date variable (i.e., "today" as YYYYMMDD) # Populate elements of array bfi[] with report names to be excluded: while (getline 0) # see P 62 of The AWK Programming Language by AKW {if (substr($0,1,1) != "#") {bfi[bf] = $0; ++bf} } } # END BEGIN # main() {idx = 0 # Gives each Report a Fair Chance to be FTPed # spin thru the array bfi[] for each row piped in from $REM2 above: for (i = 1; i <= bf; ++i) idx += index($0,bfi[i]) # is any bfi[i] in $0 ? if (idx == 0) # This lucky Report will not get excluded. {# u contains number of elements in array rep[] (the full Report Name) u = split($0, rep, "_") if (u == 4 && rep[3] == tdy) print $0 if (u == 3 && rep[2] == tdy) print $0 } }' >${YAK}/$REM1 [ ! -s "$YAK/$REM1" ] && _dang "$0" "NO MAF SCHED REPORTS FOUND FOR \"$ymd\"!" [ -z "$DDIR" ] && _dang "$0" "WORKING DIRECTORY VARIABLE \"$DDIR\" NOT SET!" if [ -d "$DDIR" ] then echo "\nRemoving OLD Daily Directory: \"$DDIR\".\n" rm -rf $DDIR # kill off anything left from yesterday, including $DDIR fi if [ -d "$MDIR" ] then echo "\nRemoving OLD Monthly Directory: \"$MDIR\".\n" rm -rf $MDIR # kill off anything left from yesterday, including $MDIR fi mkdir $DDIR 2>/dev/null # to hold Daily Reports [[ ! -d "$DDIR" ]] && _dang "$0" "DAILY REPORT DIRECTORY \"$DDIR\" MISSING!" chmod 777 "${DDIR}" 2>/dev/null mkdir "${MDIR}" 2>/dev/null # to hold Monthly Reports (if any) [[ ! -d "${MDIR}" ]] && _dang "$0" "MONTHLY REP DIRECTORY \"$MDIR\" MISSING!" chmod 777 "${MDIR}" 2>/dev/null mon=`date '+%b'` # this month (Jan thru Dec) LMO="zzz" # Last MOnth ( imaginary default) case "${mon}" in Jan) LMO="Dec" ;; Feb) LMO="Jan" ;; Mar) LMO="Feb" ;; Apr) LMO="Mar" ;; May) LMO="Apr" ;; Jun) LMO="May" ;; Jul) LMO="Jun" ;; Aug) LMO="Jul" ;; Sep) LMO="Aug" ;; Oct) LMO="Sep" ;; Nov) LMO="Oct" ;; Dec) LMO="Nov" ;; *) LMO="zzz" ;; esac >${YAK}/$REM2 # clean 'er out while read rpt do ty=`echo $rpt | awk ' {u = split($1, rep, "_") # u contains number of elements in array rep[] if (u == 4) print substr(rep[4],1,1) else if (u == 3) print substr(rep[3],1,1) else print "D" }'` # Finally, copy Reports for $ymd (whose names are in $YAK/$REM1) # into either $DDIR or $MDIR as the case deems appropriate: case "${ty}" in M) TYPE='MONTHLY'; cp ${RDIR}/${rpt} ${MDIR} ;; D) TYPE=' DAILY '; cp ${RDIR}/${rpt} ${DDIR} ;; *) TYPE='UNKNOWN'; cp ${RDIR}/${rpt} ${DDIR} ;; esac echo "${TYPE} Report: ${RDIR}/$rpt" | tee -a ${YAK}/$REM2 # Note that $REM1 contains only "pure" and complete Report Names. done <${YAK}/$REM1 # Typical Report-Names: ArchiveDropByNei_9472_19990112_D.rep # AccessDropByQr_28528_19990112_M.rep SN=`uname -a | awk '{print $2}'` # name of this server uzr="`logname` ($LOGNAME)" [ -z "$uzr" ] && uzr="UNKNOWN" ima=`awk '{if ($2 == sn) printf("%s (%s)\n", $1, sn)}' sn="$SN" /etc/hosts` [ -z "$ima" ] && ima="$SN" # BLK=16 # One (and one only) BLK must be uncommented # BLK=24 # BLK=36 # BLK=48 BLK=56 # FTP Default # BLK=64 # FTP Max cat << BOX | tee ${YAK}/$REM1 $TYPE FTP OF MAF SCHEDULED REPORTS BEGINS --------------------------------------------------------------------- TO: $IP ($SV) $YK Server FROM: $ima USER: $uzr NOTES: The complete log of this event may be found on $ima within file: "$YAK/$REM2" The most recent Daily Reports will always be in Directory "01" The most recent Monthly Reports are now under the Directory "$LMO" CURRENT BEGINNING NETWORK STATISTICS (traceroute $IP): BOX date >>${YAK}/$REM1 traceroute $IP >>${YAK}/$REM1 echo >>${YAK}/$REM1 cat ${YAK}/$REM2 >>${YAK}/$REM1 cp ${YAK}/$REM1 ${YAK}/$REM2 echo "EOF" >>${YAK}/$REM1 chmod 666 ${YAK}/$REM1 ${YAK}/$REM2 2>/dev/null # ALERT: The FTP opening directory MUST be positioned immediately above # the $NTRD directory (this is true for now but may change later!) # There MUST NOT be any blank lines between the ftp commands below! # Now, IFF we are in DAILY mode, then FTP the Daily Reports: if [[ "${1}" = "DAILY" ]] then # Here's where it all happens, folks... ftp -B $BLK $IP << FTP >>${YAK}/$REM2 debug 1 pwd ls cd $NTRD pwd mkdir 0 cd 0 lcd $YAK lcd . ascii put $REM1 lcd $DDIR pwd lcd . prompt mput * ls cd ../36 mdelete * cd .. pwd rmdir 36 rename 35 36 rename 34 35 rename 33 34 rename 32 33 rename 31 32 rename 30 31 rename 29 30 rename 28 29 rename 27 28 rename 26 27 rename 25 26 rename 24 25 rename 23 24 rename 22 23 rename 21 22 rename 20 21 rename 19 20 rename 18 19 rename 17 18 rename 16 17 rename 15 16 rename 14 15 rename 13 14 rename 12 13 rename 11 12 rename 10 11 rename 09 10 rename 08 09 rename 07 08 rename 06 07 rename 05 06 rename 04 05 rename 03 04 rename 02 03 rename 01 02 rename 0 01 bye FTP fi # Now, IFF we are in MONTHLY mode, then FTP the Monthly Reports: if [[ "${1}" = "MONTHLY" ]] then ftp -B $BLK $IP << FTP >>${YAK}/$REM2 debug 1 prompt ascii pwd ls cd $NTRD pwd lcd $YAK lcd . cd $LMO pwd mdelete * put $REM1 lcd $MDIR lcd . mput * ls lcd .. bye FTP fi cat << BOX >>${YAK}/$REM2 --------------------------------------------------------------------- FTP OF MAF SCHEDULED REPORTS ENDS: TO: $IP ($SV) $YK Server FROM: $ima USER: $uzr NOTES: The complete log of this event may be found on $ima within file: "$YAK/$REM2" The most recent Daily Reports will always be in Directory "01" The most recent Monthly Reports are now under the Directory "$LMO" CURRENT ENDING NETWORK STATISTICS (traceroute $IP): BOX date >>${YAK}/$REM2 traceroute $IP >>${YAK}/$REM2 echo "EOF" >>${YAK}/$REM2 tail -13 ${YAK}/$REM2 # Reveal ending stats rm -rf $DDIR # get rid of the Daily Report Directory rm -rf $MDIR # get rid of the Monthly Report Directory # ***************************************************************************** # EOF reps2nt.sh