%! % POSTSCRIPT WEB ERROR FILE INTERPRETER UTILITIES % =================================================================== % by Don Lancaster September 28, 1997 % =================================================================== % Copyright c 1997 by Don Lancaster and Synergetics, Box 809, % Thatcher AZ, 85552. (520) 428-4073 www.tinaja.com don@tinaja.com % All commercial rights and all electronic media rights are % *fully* reserved. Linking welcome. Reposting is expressly forbidden. % =================================================================== % These utilities are intended to be sent to the Adobe Acrobat % Distiller 3.01 by modifying this file with an editor, dragging, % and dropping. GhostScript use is possible but is not supported. % =================================================================== % WARNING: Preliminary and possibly buggy code. For advanced users only. % =================================================================== % This is yet another series of PostScript-as-language examples. % The routines are intended to read a disk based Apache web server % error file and extract only the ACCESS errors, compiling them by % frequency. This ignores all ISP caused errors and prioritizes the % remaining ones to ease their correction. /filedict 1 dict def /progress 0 def % progress marker % high level code to extract error info into PostScript dictionary... /extractaccesserrors { (starting error file extraction) print flush errorfilename (r) file /source exch def {source 1000 string readline {procline}{procline exit} ifelse }loop } def % procline unifies the line processing tasks into one job /procline {dup length 5 gt {parseline markprogress} if } def /progress 0 def /markprogress {/progress progress 1 add store progress 3000 mod 0 eq {(.) print flush} if} def % /parseline continues the log line separation, isolating the customer % data, data data, file data, and access data /parseline { (access to /) search % look for access error { pop pop % extract rest of line ( ) search % extract {exch pop exch pop addtofile }{strange_access_without_spaces} ifelse } {pop} ifelse } def % addtofile sees if the error is already in filedict. If so, % count is incremented, if not file is added to filedict with % a count of one. /addtofile { /curfilename exch store filedict curfilename cvn known { filedict curfilename cvn get % read existing file 1 add filedict exch curfilename cvn exch put } % and increment count {filedict curfilename 1 put} ifelse } def /reportaccesserrors {reportfilename (w) file /target exch def filedict { dup minerrors ge { exch 100 string cvs ( -- ) mergestr exch 10 string cvs mergestr (\n) mergestr target exch writestring } {pop} ifelse } forall } def /sortandreportaccesserrors {reportfilename (w) file /target exch def mark filedict { dup minerrors ge { [ 3 1 roll ] }{pop pop} ifelse} forall ] matbubblesort /sortedmat exch store target (\n\nTinaja access error report:\n\n) writestring sortedmat {dup 0 get 140 string cvs exch 1 get dup 1000 lt {( ) target exch writestring} if dup 100 lt {( ) target exch writestring} if dup 10 lt {( ) target exch writestring} if 10 string cvs target exch writestring target ( - ) writestring target exch writestring (\n) target exch writestring } forall target (\n\n) writestring } def % mergestr merges the two top stack strings into one top stack string /mergestr {2 copy length exch length add string dup dup 4 3 roll 4 index length exch putinterval 3 1 roll exch 0 exch putinterval} def % bubblesort accepts an array of up to 5000 elements on the stack top % and does a classic bubble sort, replacing it with a similar array % whose LARGEST value is first and SMALLEST value is last. /matbubblesort {mark exch aload pop counttomark /idx exch def { 0 1 idx 1 sub {pop 2 copy 1 get exch 1 get exch % use mat value not mat itself lt {exch} if idx 1 roll} for idx 1 roll /idx idx 1 sub def idx 0 eq {exit} if} loop ] } def % ////////////// demo - remove or alter before reuse //////////////// % WARNING: Be sure to use "\\" when you mean "\" in any file string! /errorfilename (c:\\Windows\\Desktop\\Zeketo~1\\tinaja-error_log) def /reportfilename (c:\\Windows\\Desktop\\PSLOGG~1\\errors) def /minerrors 5 def % minimum error frequency to report extractaccesserrors sortandreportaccesserrors % Simple demo currently should return extracts something like... %% %% Tinaja access error report: %% %% 35 - usr/home/tinaja/public_html/lgib %% 20 - usr/home/tinaja/public_html/News %% 15 - usr/home/tinaja/public_html/beewb02.html %% 12 - usr/home/tinaja/public_html/text/flutbarg.html %% 11 - usr/home/tinaja/public_html/image %% 9 - usr/home/tinaja/public_html/index.htm %% 8 - usr/home/tinaja/public_html/psutils/index.html %% 7 - usr/home/tinaja/public_html/text/index.html %% 6 - usr/home/tinaja/public_html/www.hotpools.com %% 6 - usr/home/tinaja/public_html/glib/hack84.pdf %% 6 - usr/home/tinaja/public_html/av %% 6 - usr/home/tinaja/public_html/glib/hack77.pdf %% 5 - usr/home/tinaja/public_html/scott/index.html %% 5 - usr/home/tinaja/public_html/glib/emergop3.pdf %% 5 - usr/home/tinaja/public_html/glib/hack16.pdf %% 5 - usr/home/don/public_html %% 5 - usr/home/tinaja/public_html/images %% 5 - usr/home/tinaja/public_html/file: %% % %%%%%%%%%%%%%%% END POSTSCRIPT ERROR REPORTER UTILITIES %%%%%%%%%%%%%%% % Consulting services available on concepts shown. % =================================================================== % Copyright c 1997 by Don Lancaster and Synergetics, Box 809, % Thatcher AZ, 85552. (520) 428-4073 www.tinaja.com don@tinaja.com % All commercial rights and all electronic media rights are % *fully* reserved. Linking welcome. Reposting expressly forbidden. % ===================================================================