program conlog !++ ! ! CONLOG.BAS -- Read last n lines from 85xx console log ! ! This program opens the 85xx console logfile (CSA3:[console]LOGFILE.DAT) ! and extracts the last n lines (n is user supplied) of data from it. ! The logfile is parsed to extract lines in a useful form for subsequent ! analysis using a text editor or file viewing utility. ! ! The logfile consists of a header block, and n (in this case 6000) data ! blocks. It is written to as a ring buffer, with context information ! held in the first few words of the header block. Records in the buffer ! are delimited by CR, LF pairs; in essence, an exact dump of what has ! appeared on the console terminal, although escape characters are ! converted to dollar signs. ! ! The program works by extracting the size of the file, current block ! and offset within current block from the header block. It then works ! backward from the current position filling out a string array, most ! recent line first. When the required number of lines have been ! extracted, the program reverses through the array, outputing the lines ! in the correct order. ! ! It appears that the contents of the last block and the header ! information don't always match; often there will be old data in the ! output file. This appears to be a problem with the header block being ! flushed to disk, but the data block remaining in memory on the Pro 350 ! console processor. There seems to be little that can be done about ! this. ! ! Note that for thie program to work, the console must be connect and the ! Pro 350 hard disk mounted. To do this, use: ! ! $ MCR SYSGEN ! SYSGEN> CONNECT CONSOLE ! SYSGEN> EXIT ! $ MOUNT/NOWRITE/SYSTEM CSA3: PROVOLUME ! ! The /NOWRITE is very important. Attempting to mount the console hard ! disk for write will crash the system. It should be mounted systemwide ! immediately after connecting to prevent users from attemting to mount ! it privately. The console's floppy disks (CSA1: and CSA2:) are not ! affected by this, and can safely be left unmounted after connecting ! the console. ! ! Note also that the console directories on the Pro 350 are protected ! against user access; because of this, READALL privilege (or SYSPRV or ! BYPASS) is necessary to use this program. ! ! Author: Don Stokes, Phone: +64 4 496-5681 ! Government Printing Office, or: +64 4 737-320 ! Wellington, New Zealand. Fax: +64 4 734-943 ! Email: don@gp.govt.nz (work), don@zl2tnm.gp.govt.nz (home) ! or: PSI%(5301)47000028::DON ! Date: 19-Aug-1990 ! !-- option type = explicit ! ! Map the buffer for the console. ! Lay out header data ! map (logfile) word fill, blockmax, blockno, fill, fill, bytecount map (logfile) string text = 512 map (logfile) string character(1 to 512) = 1 declare long c,l, maxlines, cblk, mblk declare string outarray(10000), s, outfile ! ! Get user requirements: ! Output file name, default is SYS$OUTPUT ! Number of lines to list, default is 24 ! set no prompt linput "Output file: "; outfile outfile = "SYS$OUTPUT:" if outfile = "" input "Lines to extract: "; maxlines maxlines = 24 if maxlines = 0 maxlines = 10000 if maxlines > 10000 ! ! Open files ! open "CSA3:[console]LOGFILE.DAT" for input as file #1, & access read, allow modify, & organization sequential fixed, recordsize 512, & recordtype any, map logfile open outfile for output as file #2, recordsize 32767, & defaultname "LOGFILE.LIS" ! ! Get header record, extract current block, maximum block ! and offset into current block ! get #1 cblk = blockno mblk = blockmax c = bytecount ! ! Get current block ! get #1, record cblk ! ! Loop until we have all the lines we want ! for l = 1 to maxlines ! ! If we have gone over a block boundary, get the next block ! from the logfile and restart the character pointer at the ! top of the block. ! Read characters until we reach a line feed (CRs are ignored) ! Add character to beginning of output line. ! s = "" loop: while -1% if c < 1 then cblk = cblk - 1 cblk = mblk if cblk = 1 get #1, record cblk c = c + 512 end if exit loop unless character(c) <> lf s = character(c) + s if character(c) >= " " & or character(c) = chr$(9) c = c - 1 next ! ! Skip over linefeed and save string in array ! c = c - 1 outarray(l) = s next l ! ! Write the contents of the log array backwards into the ! output file (ends up in correct order). ! print #2, outarray(l) for l = maxlines to 1 step -1 ! ! Close files and exit ! close #1 close #2 end program