16-Jun-2014

System logical name changes

Here's a command procedure that run daily, will provide you with a nice email listing additions, deletions, and modifications to the system logical name table.


$! COMPARE_LNM.COM - report on system logical name changes.
$! See EOF for comments.
$       old_verify = f$verify (0)
$! Change this to point to a directory to contain output from SHOW LOGICAL.
$       lnmdir = "sm_root:[lnm]"
$! Change this to define who receives emails when something changes
$       email_to = "jim@example.com"
$! Define wildcarded logical names to ignore changes for.
$       ignore_list = "FTPC%%%%%%%%|PERFDAT$NEXT_ARCHIVE_DATE|" + -
                      "ACME$MAILBOX|APACHE$SERVER_PID|" + -
                      "AUDSRV$CONTROL_MAILBOX|DECW$MBX_X11*|" + -
                      "LANACP$MBX*|PERFDAT$PID|PERFDAT_COLL|" + -
                      "PERFDAT_EVA_*|PERFDAT_MGMT|REGISTRY$MAILBOX" + -
                      "TCPIP$FTP_%MBX"
$!
$       diffs = 0
$       say := write sys$output
$       now = f$time ()
$       yesterday = f$cvtime ("''now'-1-","comparison","date")
$       today = f$cvtime (now, "comparison", "date")
$       old_file = lnmdir + "lnmcompare_" + yesterday + ".txt"
$       new_file = lnmdir + "lnmcompare_" + today + ".txt"
$       diff_file = lnmdir + "diffs.txt"
$       show log/table=lnm$system_table/output='new_file'
$       gosub format
$       open/read/error=no_yesterday old 'old_file'
$       open/read new 'new_file'
$       open/write out 'diff_file'
$diff:
$       read/end_of_file=oeof old orec
$       read/end_of_file=neof new nrec
$check:
$       if orec .eqs. nrec
$       then
$           goto diff
$       endif
$       if orec .lts. nrec
$       then
$           action = "deleted"
$           drec = orec
$           gosub outf
$           read/end_of_file=oeof old orec
$           goto check
$       endif
$       if orec .gts. nrec
$       then
$           action = "added"
$           drec = nrec
$           gosub outf
$           read/end_of_file=neof new nrec
$           goto check
$       endif
$neof:
$       close new
$neofloop:
$       read/end_of_file=done old orec
$       action = "deleted"
$       drec = orec
$       gosub outf
$       goto neofloop
$oeof:
$       close old
$oeofloop:
$       read/end_of_file=done new nrec
$       action = "added"
$       drec = nrec
$       gosub outf
$       goto neofloop
$done:
$       if f$trnlnm ("old") .nes. ""
$       then
$           close old
$       endif
$       if f$trnlnm ("new") .nes. ""
$       then
$           close new
$       endif
$       close out
$       if diffs .gt. 0
$       then
$           mail/subject="Changed logical names" 'diff_file' "''mail_to'"
$       endif
$       delete/nolog 'diff_file';*
$       goto exit
$no_yesterday:
$       say "No file for yesterday.  Please schedule daily!"
$exit:
$       if f$search ("diffs.txt") .nes. ""
$       then
$           delete/nolog diffs.txt;*
$       endif
$       delete/before="-10-" 'lnmdir'lnmcompare_*.txt;*
$       exit 1 + (0*f$verify (old_verify))
$!==============================================================================
$format:
$       log = ""
$       open new 'new_file'
$       open/write newf 'new_file'
$loop:
$       read/end=end_loop new rec
$       rec = f$edit (rec, "trim")
$       if f$edit(rec, "collapse") .eqs. ""
$       then
$           goto loop
$       endif
$       if f$extract (0, 1, rec) .eqs. """"
$       then
$           if log .nes. ""
$           then
$               write/sym newf log
$           endif
$           log = rec
$       endif
$       if f$extract (0, 1, rec) .eqs. "="
$       then
$           len = f$length (rec)
$           rec = f$extract (2, len - 2, rec)
$           log = log + "," + rec
$       endif
$       goto loop
$end_loop:
$       write/sym newf log
$       close new
$       close newf
$       purge/nolog 'new_file'
$       return
$!==============================================================================
$outf:
$       len = f$length (drec)
$       eq = f$locate (" = ", drec)
$       logical = f$extract (0, eq, drec)
$       eqvs = f$extract (eq + 3, len - eq - 3, drec)
$       len = f$length (eqvs)
$       eq = f$locate (""",""", eqvs)
$       check_more = 0
$       if eq .eq. len
$       then
$           eqv = eqvs
$       else
$           check_more = 1
$           eqv = f$extract (0, eq, eqvs)
$           eqvs = f$extract (eq + 2, len - eq - 2, eqvs)
$       endif
$       report = 1
$       gosub ignore
$       if .not. report
$       then
$           goto exit_outf
$       endif
$       diffs = diffs + 1
$       write out "Logical name ''action': "
$       write out "    " + logical + " = " + eqv
$recheck:
$       if check_more
$       then
$           len = f$length (eqvs)
$           eq = f$locate (""",""", eqvs)
$           check_more = 0
$           if eq .eq. len
$           then
$               eqv = eqvs
$           else
$               check_more = 1
$               eqv = f$extract (0, eq, eqvs)
$               eqvs = f$extract (eq + 2, len - eq - 2, eqvs)
$           endif
$           write out "        = " + eqvs
$           goto recheck
$       endif
$       write out ""
$exit_outf:
$       return
$
$!==============================================================================
$ignore:
$       match_cnt = 0
$iloop:
$       match = f$element (match_cnt, "|", ignore_list)
$       if match .eqs. "|"
$       then
$           goto end_iloop
$       endif
$       match = """" + match + """"
$say logical
$say match
$       if f$match_wild (logical, match)
$       then
$           report = 0
$           goto end_iloop
$       endif
$       match_cnt = match_cnt + 1
$       goto iloop
$end_iloop:
$       return 1
$
$!++
$!
$! DESCRIPTION
$!
$!       This command procedure is designed to run once a day and report on any
$!       system logical names that have been added, deleted, or changed.
$!       If it finds changes, it sends email.
$!
$! AUTHOR
$!
$!       James F. Duff (http://www.eight-cubed.com/)
$!
$! MODIFICATION HISTORY
$!
$!      ??-???-2011    Jim Duff
$!      Original version of code.
$!
$!      10-Oct-2012    Jim Duff
$!      Cleaned up and productionalised.
$!
$!      22-Oct-2012    Jim Duff
$!      Add ignore_list functionality.
$!--

Posted at June 16, 2014 5:21 PM
Tag Set:

Comments are closed