/* REXX TRIMLOG remove old entries from LOG.MISC Written by Frank Clarke 20010323 Impact Analysis . SYSPROC TRAPOUT Modification History 20010503 fxc use vb4k. ; 20010614 fxc HBACKDS archfile; 20020311 fxc short retention for LOG; WIDEHELP; */ arg argline address TSO /* REXXSKEL ver.19991109 */ parse arg parms "((" opts signal on syntax signal on novalue call TOOLKIT_INIT /* conventional start-up -*/ rc = Trace("O"); rc = trace(tv) info = parms /* to enable parsing */ call A_INIT /* -*/ call C_SCAN_LOG /* -*/ call D_REWRITE /* -*/ call ZB_SAVELOG /* -*/ if \sw.nested then call DUMP_QUEUE /* -*/ exit /*@ TRIMLOG */ /* Initialization . ----------------------------------------------------------------- */ A_INIT: /*@ */ if branch then call BRANCH address TSO call A0_SETUP_LOG /* */ call ZL_LOGMSG("Log started by" Userid() yyyymmdd hhmmss) call AA_KEYWDS /* -*/ today_b = Date("B") thresh_b = today_b - limit /* threshold basedate */ mon. = "???" parse value "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" with, mon.jan mon.feb mon.mar mon.apr mon.may mon.jun, mon.jul mon.aug mon.sep mon.oct mon.nov mon.dec return /*@ A_INIT */ /* Init LOG dataset allocation parameters. . ----------------------------------------------------------------- */ A0_SETUP_LOG: /*@ */ if branch then call BRANCH address TSO parse value "0" with, log# log. parse value Date("S") Time("S") Time("N") with, yyyymmdd sssss hhmmss . parse var yyyymmdd 4 yrdigit 5 mm 7 dd /* 9 12 14 maybe */ if Pos(yrdigit,"13579") > 0 then mm = mm + 12 /* mm=24 */ logtag = Substr("ABCDEFGHIJKLMNOPQRSTUVWX",mm,1) /* logtag=X */ subid = logtag""dd""Right(sssss,5,0) /* X1423722 ? */ vb4k.0 = "NEW CATALOG UNIT(SYSDA) SPACE(1 5) TRACKS", "RECFM(V B) LRECL(4096) BLKSIZE(0)" vb4k.1 = "SHR" /* if it already exists... */ logdsn = "@@LOG."exec_name"."subid".#CILIST" return /*@ A0_SETUP_LOG */ /* Parse out KEYWD parameters . ----------------------------------------------------------------- */ AA_KEYWDS: /*@ */ if branch then call BRANCH address TSO parse value KEYWD("LIMIT") "60" with, limit . parse value KEYWD("ARCHIVE") with, archfile . parse value KEYPHRS("MARKER") with, marker if marker = "" & archfile <> "" then do helpmsg = "MARKER and ARCHIVE must both be specified or" , "unspecified." call HELP /* ...and don't come back -*/ end if marker <> "" & archfile = "" then do helpmsg = "MARKER and ARCHIVE must both be specified or" , "unspecified." call HELP /* ...and don't come back -*/ end return /*@ AA_KEYWDS */ /* Acquire the contents of the LOG dataset and examine it for old entries. Data delineated by the text of (through the next start-of-message line) will be written to the queue and erased from the stem array regardless of date. Old entries will be erased from the stem array. At end-of-stem, the contents of the queue will be written to file ARCHIVE if such exists. . ----------------------------------------------------------------- */ C_SCAN_LOG: /*@ */ c_tv = trace() /* what setting at entry ? */ if branch then call BRANCH address TSO "ALLOC FI($LOG) DA("logds") SHR REU" if rc > 0 then do /* Oops... */ helpmsg = "Specified or implied LOGdataset must exist." call HELP /* ...and don't come back! -*/ end "EXECIO * DISKR $LOG (STEM $log. FINIS" "NEWSTACK" do cx = 1 to $log.0 /* every line */ if Left($log.cx,60) = Copies("-",60) then do /* separator */ if sw.0purge then do /* OK to purge group */ do cxa = startpt to endpt $log.cxa = "" end /* purge */ call ZL_LOGMSG("Group purged") end /* purge */ parse value cx cx "0" "0" with, endpt startpt sw.0spool sw.0purge . call ZL_LOGMSG("Start of group:" cx) iterate end endpt = cx /* currrent line is endpt */ if Word($log.cx,1) = "RECEIVE" | , Word($log.cx,1) = "TRANSMIT" then do parse var $log.cx 63 date 74 . /* dd mmm yyyy */ date = CA_CONVERT(date) /* put it in proper form -*/ then_b = Date("B",date,"N") /* convert to base */ if then_b < thresh_b then do /* too old */ sw.0purge = "1" /* lose this group */ call ZL_LOGMSG("PURGE set for" date) end iterate end if marker = "" then iterate /* no special cases */ if sw.0spool then do /* archiving */ queue $log.cx /* save this */ call ZL_LOGMSG("Spooled" $log.cx) iterate end thismark = "" /* init */ do Words(marker) parse value marker thismark with thismark marker if Pos(thismark,Translate($log.cx)) > 0 then do parse value "1" "1" with, sw.0purge sw.0spool . call ZL_LOGMSG("SPOOL set at" cx) queue $log.cx /* */ end end /* words(marker) */ marker = marker thismark end /* cx */ if sw.0purge then do do cxa = startpt to endpt $log.cxa = "" end /* purge */ call ZL_LOGMSG("Group purged") end /* purge */ rc = Trace("O"); rc = trace(c_tv) if queued() > 0 then do /* stuff to save */ call CS_SAVE_SPOOL /* write on ARCHFILE -*/ end /* queued */ "DELSTACK" return /*@ C_SCAN_LOG */ /* Date arrives as, for example, '09 JUN 2001' but the REXX Date routines require it as '9 Jun 2001'. . ----------------------------------------------------------------- */ CA_CONVERT: /*@ */ if branch then call BRANCH address TSO arg date /* in DD MMM YYYY form */ parse var date dd mmm yyyy . dd = dd + 0 /* drop leading zero */ date = dd mon.mmm yyyy /* convert month to dual-case */ return(date) /*@ CA_CONVERT */ /* Save the stuff on the queue. Allocate MOD . ----------------------------------------------------------------- */ CS_SAVE_SPOOL: /*@ */ if branch then call BRANCH address TSO alloc.0 = "NEW CATALOG UNIT(SYSDA) SPACE(20 20) TRACKS", "RECFM(V B) LRECL(255) BLKSIZE(0)" alloc.1 = "MOD" /* if it already exists... */ tempstat = Sysdsn(archfile) = "OK" /* 1=exists, 0=missing */ "ALLOC FI($TMP) DA("archfile") REU" alloc.tempstat if \noupdt then, "EXECIO" queued() "DISKW $TMP (FINIS" "FREE FI($TMP)" "HBACKDS" archfile return /*@ CS_SAVE_SPOOL */ /* Along the way, any line which was to be purged was blanked out. Get all non-blank rows and write them back to the LOG. . ----------------------------------------------------------------- */ D_REWRITE: /*@ */ if branch then call BRANCH address TSO "NEWSTACK" do dx = 1 to $log.0 /* every log entry */ if $log.dx <> "" then, /* ...that isn't blank */ queue $log.dx end /* dx */ if \noupdt then, "EXECIO" queued() "DISKW $LOG (FINIS" "FREE FI($LOG)" "DELSTACK" return /*@ D_REWRITE */ /* Parse non-standard parameters . ----------------------------------------------------------------- */ LOCAL_PREINIT: /*@ customize opts */ address TSO parse value KEYWD("LOGDS") "LOG.MISC" with, logds . return /*@ LOCAL_PREINIT */ /* subroutines below LOCAL_PREINIT are not selected by SHOWFLOW */ /* Write LOGFILE entries. . ----------------------------------------------------------------- */ ZB_SAVELOG: /*@ */ if branch then call BRANCH address TSO if Symbol("LOG#") = "LIT" then return /* not yet set */ "ALLOC FI($LOG) DA("logdsn") REU" vb4k.0 "EXECIO" log# "DISKW $LOG (STEM LOG. FINIS" "FREE FI($LOG)" return /*@ ZB_SAVELOG */ /* Post LOG message to the LOG. array . ----------------------------------------------------------------- */ ZL_LOGMSG: Procedure expose, /*@ */ (tk_globalvars) log. log# rc = Trace("O") address TSO parse arg msgtext parse value log#+1 msgtext with, zz log.zz 1 log# . if monitor then say, msgtext return /*@ ZL_LOGMSG */ /* . ----------------------------------------------------------------- */ HELP: /*@ */ address TSO;"CLEAR" if helpmsg <> "" then do ; say helpmsg; say ""; end ex_nam = Left(exec_name,8) /* predictable size */ say " "ex_nam" examines LOG.MISC and discards any entries older than 60 " say " days. Entries which are neither TRANSMIT nor RECEIVE " say " entries for messages or datasets will be retained " say " unconditionally. " say " " say " Syntax: "ex_nam" (Defaults) " say " " say " " say " (( (Defaults) " say " " say " # if specified replaces the default value of 60 days " say " for retention of old entries. " say " " say " afile is the TSO-format name of your archive dataset. It " say " must be an allocatable dataset. If is " say " specified, must also be specified. " say " " say " mark is a list of words in KEYPHRS format each of which " say " denotes a group of lines to be moved to the archive " say " file. If is specified, must also be " say " specified. " say " " say " dsn designates an alternate LOG dataset. Default is " say " 'LOG.MISC' " "NEWSTACK"; pull ; "CLEAR" ; "DELSTACK" say " Debugging tools provided include: " say " " say " MONITOR: displays key information throughout processing. " say " " say " NOUPDT: by-pass all update logic. " say " " say " BRANCH: show all paragraph entries. " say " " say " TRACE tv: will use value following TRACE to place the execution in" say " REXX TRACE Mode. " say " " say " " say " Debugging tools can be accessed in the following manner: " say " " say " TSO "ex_nam" parameters (( debug-options " say " " say " For example: " say " " say " TSO "ex_nam" (( MONITOR TRACE ?R " address ISPEXEC "CONTROL DISPLAY REFRESH" exit /*@ HELP */ /* . ----------------------------------------------------------------- */ BRANCH: Procedure expose, /*@ */ sigl exec_name rc = trace("O") /* we do not want to see this */ arg brparm . origin = sigl /* where was I called from ? */ do currln = origin to 1 by -1 /* inch backward to label */ if Right(Word(Sourceline(currln),1),1) = ":" then do parse value sourceline(currln) with pgfname ":" . /* Label */ leave ; end /* name */ end /* currln */ select when brparm = "NAME" then return(pgfname) /* Return full name */ when brparm = "ID" then do /* wants the prefix */ parse var pgfname pgfpref "_" . /* get the prefix */ return(pgfpref) end /* brparm = "ID" */ otherwise say left(sigl,6) left(pgfname,40) exec_name "Time:" time("L") end /* select */ return /*@ BRANCH */ /* . ----------------------------------------------------------------- */ DUMP_QUEUE: /*@ Take whatever is in stack */ rc = trace("O") /* and write to the screen */ address TSO "QSTACK" /* how many stacks? */ stk2dump = rc - tk_init_stacks /* remaining stacks */ if stk2dump = 0 & queued() = 0 then return say "Total Stacks" rc , /* rc = #of stacks */ "Begin Stacks" tk_init_stacks , /* Stacks present at start */ "Stacks to DUMP" stk2dump do dd = rc to tk_init_stacks by -1 /* empty each one. */ say "Processing Stack #" dd "Total Lines:" queued() do queued();pull line;say line;end /* pump to the screen */ "DELSTACK" /* remove stack */ end /* dd = 1 to rc */ return /*@ DUMP_QUEUE */ /* . ----------------------------------------------------------------- */ KEYWD: Procedure expose info /*@ hide all vars, except info*/ arg kw kw_pos = wordpos(kw,info) /* find where it is, maybe */ if kw_pos = 0 then return "" /* send back a null, not found*/ kw_val = word(info,kw_pos+1) /* get the next word */ info = Delword(info,kw_pos,2) /* remove both */ return kw_val /*@ KEYWD */ /* . ----------------------------------------------------------------- */ KEYPHRS: Procedure expose, /*@ */ info helpmsg exec_name /* except these three */ arg kp wp = wordpos(kp,info) /* where is it? */ if wp = 0 then return "" /* not found */ front = subword(info,1,wp-1) /* everything before kp */ back = subword(info,wp+1) /* everything after kp */ parse var back dlm back /* 1st token must be 2 bytes */ if length(dlm) <> 2 then /* Must be two bytes */ helpmsg = helpmsg "Invalid length for delimiter("dlm") with KEYPHRS("kp")" if wordpos(dlm,back) = 0 then /* search for ending delimiter*/ helpmsg = helpmsg "No matching second delimiter("dlm") with KEYPHRS("kp")" if helpmsg <> "" then call HELP /* Something is wrong */ parse var back kpval (dlm) back /* get everything b/w delim */ info = front back /* restore remainder */ return Strip(kpval) /*@ KEYPHRS */ /* . ----------------------------------------------------------------- */ NOVALUE: /*@ */ say exec_name "raised NOVALUE at line" sigl say " " say "The referenced variable is" condition("D") say " " zsigl = sigl signal SHOW_SOURCE /*@ NOVALUE */ /* . ----------------------------------------------------------------- */ SHOW_SOURCE: /*@ */ call DUMP_QUEUE /* Spill contents of stacks -*/ if sourceline() <> "0" then /* to screen */ say sourceline(zsigl) rc = trace("?R") nop exit /*@ SHOW_SOURCE */ /* . ----------------------------------------------------------------- */ SS: Procedure /*@ Show Source */ arg ssbeg ssend . if ssend = "" then ssend = 10 if \datatype(ssbeg,"W") | \datatype(ssend,"W") then return ssend = ssbeg + ssend do ssii = ssbeg to ssend ; say sourceline(ssii) ; end return /*@ SS */ /* . ----------------------------------------------------------------- */ SWITCH: Procedure expose info /*@ */ arg kw sw_val = Wordpos(kw,info) > 0 /* exists = 1; not found = 0 */ if sw_val then /* exists */ info = Delword(info,Wordpos(kw,info),1) /* remove it */ return sw_val /*@ SWITCH */ /* . ----------------------------------------------------------------- */ SYNTAX: /*@ */ errormsg = exec_name "encountered REXX error" rc "in line" sigl":", errortext(rc) say errormsg zsigl = sigl signal SHOW_SOURCE /*@ SYNTAX */ /* Can call TRAPOUT. . ----------------------------------------------------------------- */ TOOLKIT_INIT: /*@ */ address TSO info = Strip(opts,"T",")") /* clip trailing paren */ parse source sys_id how_invokt exec_name DD_nm DS_nm, as_invokt cmd_env addr_spc usr_tokn parse value "" with tv helpmsg . parse value 0 "ISR00000 YES" "Error-Press PF1" with, sw. zerrhm zerralrm zerrsm if SWITCH("TRAPOUT") then do "TRAPOUT" exec_name parms "(( TRACE R" info exit end /* trapout */ if Word(parms,1) = "?" then call HELP /* I won't be back */ "QSTACK" ; tk_init_stacks = rc /* How many stacks? */ parse value SWITCH("BRANCH") SWITCH("MONITOR") SWITCH("NOUPDT") with, branch monitor noupdt . parse value mvsvar("SYSNAME") sysvar("SYSNODE") with, #tk_cpu node . sw.nested = sysvar("SYSNEST") = "YES" sw.batch = sysvar("SYSENV") = "BACK" sw.inispf = sysvar("SYSISPF") = "ACTIVE" parse value KEYWD("TRACE") "O" with tv . tk_globalvars = "tk_globalvars exec_name tv helpmsg sw. zerrhm", "zerralrm zerrsm zerrlm tk_init_stacks branch", "monitor noupdt" call LOCAL_PREINIT /* for more opts -*/ return /*@ TOOLKIT_INIT */