home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / inetlog3.zip / inetlog.cmd < prev    next >
OS/2 REXX Batch file  |  1995-03-18  |  14KB  |  350 lines

  1. /* INETLOG.CMD  REXX Program to extract and totalize daily and monthly    */
  2. /* time-ons by analyzing the IBM WARP Internet Dialer CONNECT.LOG file    */
  3. /*                                            */
  4. /* Jerry Levy,  Marblehead, MA     18 Mar 95                    */
  5. /* Please pass on comments, suggestions, problems to JLEVY@IBM.NET        */
  6. /* -------------------------------------------------------------    */
  7. /*Program History                                    */
  8. /*  1.0    12 Feb 95    First distribution                        */
  9. /*  2.0    05 Mar 95                                                                */
  10. /*     -Cleaned up program                                */
  11. /*    -Added some more error traps                        */
  12. /*    -Changed all rounding to nearest .01 minutes:  Advantis calculates        */
  13. /*     online time to nearest second, and .01 mins is quite close enough        */
  14. /*    -Use_VRexx equate was added: bypasses VRexx if not = "YES"        */
  15. /*  3.0    18 Mar 95                                     */
  16. /*    -Corrected output filename bug introduced into 2.0                */
  17. /*    -Added pausing to prevent scrolling of output off screen            */
  18. /*    -Added to documentation                            */
  19. /*    -Added EOF2CRLF.CMD which strips out End-of-File Charcters (see Doc'n)    */
  20. /*    -Distribution package no longer contains the VRexx files.  Suggested    */
  21. /*     is you download the whole VREXX2.ZIP separately (See Doc'n)        */
  22. /*    -Default setup disables VRexx, therefore.  Re-enableit  if you have VRexx2    */
  23. /*                                            */
  24. /* -------------------------------------------------------------    */
  25. /* GETTING STARTED (See ReadMe.1st for more detail)                */
  26. /* The surest way is to place all files extracted after unzipping INETLOG.ZIP,    */
  27. /* into asingle folder.  No matter where that folder is placed double-clicking on    */
  28. /* INETLOG.CMD will start the program properly.  If the OS/2 window does not    */
  29. /* stay open after everything scrolls by, go into the INETLOG.CMD Settings        */
  30. /* Notebook, go to the Sessions Page, and de-select "Close Window on Exit".    */
  31. /*                                            */
  32. /* You must, of course, have set up your IBM Information Highway Internet        */
  33. /* Dialer to log, and you must know the location and name of the logfile,  usually    */
  34. /* c:\tcpip\etc\connect.log.  If you have problems, read through the README.1ST    */
  35. /* file.     Further information on the connection logfile can be found in LOGFILE.TXT*/                
  36. /* -------------------------------------------------------------    */
  37.  
  38. /* Customize these five items if you need to.  Don't forget the quotation marks    */
  39. /* for the first two as the equates aren't syntactically correct without them        */
  40.  
  41.    log_file = "c:\tcpip\etc\connect.log"    /* Complete path and filespec for the log file    */
  42.  
  43.    output_file = "c:\tcpip\etc\file.$$$"     /* File you want output saved to        */
  44.  
  45.    Use_VRexx = "NO"            /* YES means we prompt for filenames    */
  46.                     /* using VREXX dialog boxes            */
  47.  
  48.    one_screen_atatime = "YES"    /* Pause each screen?            */
  49.  
  50.  
  51. /* -------------------------------------------------------------    */
  52.  
  53.  
  54. What_R_We = "INETLOG.CMD  v. 3.0     Jerry Levy"
  55.  
  56. Use_VRexx = translate(Use_VRexx)    /* so we accept upper, lower case yes'es    */
  57. one_screen_atatime = translate(one_screen_atatime)
  58.  
  59. signal on failure name CLEANUP
  60. signal on halt name CLEANUP
  61. signal on syntax name CLEANUP
  62. signal on error name CLEANUP
  63. signal on notready name CLEANUP
  64.  
  65. /* Load the REXXUTIL functions    */
  66.  
  67.    call rxfuncadd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  68.    call sysloadfuncs
  69.  
  70. crlf = d2c(13)||d2c(10)    /* carriage return + linefeed    */
  71.  
  72. /* initialize all of these    */
  73.  
  74. month.01 = "Jan"
  75. month.02 = "Feb"
  76. month.03 = "Mar"
  77. month.04 = "Apr"
  78. month.05 = "May"
  79. month.06 = "Jun"
  80. month.07 = "Jul"
  81. month.08 = "Aug"
  82. month.09 = "Sep"
  83. month.10 = "Oct"
  84. month.11 = "Nov"
  85. month.12 = "Dec"
  86.  
  87. dcounter = 0            /* Counter increments each sign-on in a day        */
  88. mcounter = 0            /* Same for each sign-on in a month            */
  89. signons_each_day = 0    /* Accumulate number of connects daily        */
  90. signons_each_month = 0    /* Accumulate number of connects monthly        */
  91. TimeOn = 0            /* Time, each connect  (minutes)            */
  92. DailyTimeOn = 0        /* Accumulated minutes, daily            */
  93. MonthlyTimeOn = 0        /* Accumulated minutes, monthly            */ 
  94. old_m = 0            /* Storage of a 2-digit month (eg 05 = May)        */
  95. old_d = 0            /* and a 2-digit day                    */ 
  96.  
  97. monthline = ""            /* Initialize both of these as null strings        */
  98. dayline = ""            /* These are for monthly and daily output strings    */
  99.  
  100. /* A typical line generated in the connect.log upon disconnect looks like this:     */
  101. /*       11/15 19:08:38 Disconnected after 00:06:20  0 errors  0 discards        */
  102. /* so we search for a key_phrase using the RexxUtil function SysFileSearch    */
  103.  
  104.     key_phrase = "Disconnected after"    /* Word or phrase we"ll search for    */
  105.  
  106. /* Now we Initialize VREXX    */
  107.  
  108. if Use_VRexx = "YES" then
  109.    do                                /* Start up VREXX    */
  110.       "@echo off"
  111.       call RxFuncAdd "VInit", "VREXX", "VINIT"
  112.       initcode = VInit()
  113.       if initcode = "ERROR" then signal CLEANUP
  114.    end
  115.  
  116.  if Use_VRexx = "YES" then                         /* Select logfile    */
  117.       do until result <> ""        /* Don't accept a nonexistent filename    */
  118.          call VdialogPos 30, 50
  119.          button = VFileBox("Select File to Analyze", log_file, filename)
  120.          if button = "OK" then log_file = filename.vstring
  121.          if button = "CANCEL" then call CLEANUP
  122.  
  123.          call stream log_file, "c", "query exists"
  124.          if result = "" then
  125.             do
  126.                say log_file "does not exist, try again!"||crlf
  127.                call beep 1000,100
  128.             end
  129.       end
  130.  
  131. if Use_VRexx = "YES" then        /* Choose file for outputting to disk        */
  132.    do until prompt.vstring <> ""    /* Have to enter something.            */
  133.  
  134.       call VDialogPos 50, 50
  135.                   /* The padding with spaces below controls dialog    */
  136.                 /* box size, and prevents lopping off of last char    */
  137.                 /* consequent to use of System Proportional font    */ 
  138.       prompt.0 = 6
  139.       prompt.1 = "Include path and filename.  If file exists it will be                           "
  140.       prompt.2 = "overwritten after being saved as a .BAK file.    "
  141.       prompt.3 = ""
  142.       prompt.4 = "No wildcards are allowed.  "
  143.       prompt.5 = ""
  144.       prompt.6 = "Default dir is" directory() "if no path is indicated.    "
  145.       prompt.vstring = output_file
  146.       button =  VInputBox("Select Filename to Save Output to", prompt, 30, 3)
  147.       if button = "CANCEL" then call CLEANUP
  148.  
  149. /* We don't let you name the output file connect.log, config,sys, or autoexec.bat    */
  150.    if prompt.vstring <> "" then file = prompt.vstring
  151.    file = translate(filespec("name", file))
  152.    if file == CONNECT.LOG | file == CONFIG.SYS | file == AUTOEXEC.BAT then
  153.       do
  154.          say "Output file is" file||".  You are not allowed to"
  155.          say "use CONNECT.LOG, CONFIG.SYS, or AUTOEXEC.BAT as an output filename."||crlf
  156.          call beep 1000,100
  157.          prompt.vstring = ""
  158.      end
  159.      if prompt.vstring = "" then call beep 1000,100
  160.      if prompt.vstring <> "" then output_file = prompt.vstring
  161. end
  162.  
  163. /* Check if the output file exists.  If it does, we overwrite it. If not we create it.     */
  164. /* We also don't want to do something stupid like try to erase a vital file or the        */
  165. /* connect logfile                                        */
  166.  
  167. if Use_Vrexx <> "YES" then
  168.    do
  169.         call stream log_file, "c", "query exists"
  170.          if result = "" then
  171.             do
  172.                say "Aborting." log_file "does not exist."
  173.                say "Check for the correct logfile name at the log_file equate in INETLOG.CMD."
  174.                call beep 1000,100
  175.                call CLEANUP
  176.            end
  177.    end
  178.  
  179. if Use_VRexx <> "YES" then
  180.    do
  181.       file = translate(filespec("name", output_file))
  182.  
  183.       if file == CONNECT.LOG | file == CONFIG.SYS | file == AUTOEXEC.BAT then
  184.          do
  185.             say "Output file is" output_file||".  You are not allowed to use"
  186.             say "CONNECT.LOG, CONFIG.SYS, or AUTOEXEC.BAT as an output filename."
  187.             call beep 1000,100
  188.             call CLEANUP:                            /* Error, so Exit    */
  189.          end
  190.    end
  191.  
  192. /* Terminate VREXX if we were using it    */
  193.  
  194. if Use_VRexx = "YES" then
  195.    do
  196.       call VExit
  197.       Use_VRexx = "NO"            /* "NO", so on eventually exiting the pgm    */
  198.    end                        /* we don't re-run VExit if we've just run it    */
  199.                         /* here                        */
  200.  
  201. /* Backup any output file of the same name if it exists, then erase it            */
  202. /* SysFile Delete won't accept wildcards, by the way, so damage we can do is limited    */
  203.  
  204.         call stream output_file, "c", "query exists"
  205.         if result <> "" then
  206.             do
  207.               "@copy" output_file filespec("drive",output_file)||filespec("path",output_file)||"*.bak>NUL"
  208.                call SysFileDelete output_file
  209.            end
  210.  
  211. /* Now find all lines in connect.log that contain the key_phrase string    */
  212. /* A typical line generated in the connect.log after disconnect is:        */
  213. /*   "11/15 19:08:38 Disconnected after 00:06:20  0 errors  0 discards"    */
  214. /* which we will parse as follows:                        */
  215. /*     date  word2       word3    word4 connect_time                */  
  216.  
  217. call SysFileSearch key_phrase, log_file, "line."
  218.  
  219. RC = 0
  220.  
  221. DO i = 1 to line.0        /* the END for this "do" is in caps down below*/
  222.    parse var line.i date word2 word3 word4 connect_time
  223.  
  224.    mm = substr(date, 1, 2)    /* Extract the month of a connection as a 2-dig number*/
  225.    dd = substr(date, 4, 2)    /* ...and the day                */
  226.    hrs = substr(connect_time, 1, 2)    /* Extract the number of hours on-line*/
  227.    mins = substr(connect_time, 4, 2)    /*... and mins                */
  228.    secs = substr(connect_time, 7, 2)    /*...and seconds            */
  229.    TimeOn = (60*hrs + mins + (1/60)*secs)    /* Calculate time_on for that connection*/
  230.  
  231. IF old_d = 0 then
  232.    do                        /* for very first connection line*/
  233.       old_m = mm
  234.       old_d = dd
  235.       signons_each_day = 1            /* reset to 1    */
  236.       signons_each_month = 1
  237.       DailyTimeOn = TimeOn
  238.       MonthlyTimeOn = TimeOn
  239.    end
  240.  
  241. ELSE IF old_m = mm & old_d = dd & Month <> 0 then
  242.    do                /* continue to accumulate times if same month and day*/
  243.       signons_each_day = signons_each_day + 1
  244.       signons_each_month = signons_each_month + 1
  245.       DailyTimeOn = DailyTimeOn + TimeOn
  246.       MonthlyTimeOn = MonthlyTimeOn + TimeOn
  247.    end
  248.  
  249. ELSE IF old_m = mm & old_d <> dd then        /* new day of same month    */
  250.    do
  251.       dcounter = dcounter + 1
  252.       dayline.dcounter = old_d month.old_m "("||signons_each_day||"X)" format(DailyTimeOn, 4, 2) "mins"
  253.  
  254.       old_d = dd
  255.       signons_each_day = 1                /* Start counting over again    */
  256.       signons_each_month = signons_each_month + 1
  257.       DailyTimeOn = TimeOn
  258.       MonthlyTimeOn = MonthlyTimeOn + TimeOn
  259.    end
  260.  
  261. ELSE IF old_m <> mm & old_m <> 0 then
  262.    do                /* for any new month, which by definition is also a new day    */
  263.       dcounter = dcounter + 1
  264.       dayline.dcounter = old_d month.old_m "("||signons_each_day||"X)" format(DailyTimeOn, 4, 2) "mins"
  265.  
  266.       mcounter = mcounter + 1
  267.       monthline.mcounter = month.old_m "("||format(signons_each_month, 3)||"X)" format(MonthlyTimeOn, 5, 2) "mins"
  268.  
  269.       old_m = mm
  270.       old_d = dd
  271.       signons_each_day = 1
  272.       signons_each_month = 1
  273.       DailyTimeOn = TimeOn
  274.       MonthlyTimeOn = TimeOn
  275.    end
  276.  
  277. /* end of all these IF"s and ELSE IF"s                        */
  278.  
  279. END    /* of searching for key_phrase in all possible lines in the connect.log    */
  280.  
  281. /* Now,since last day and last month is done:                    */
  282.  
  283.          dcounter = dcounter + 1
  284.          dayline.dcounter = old_d month.old_m "("||signons_each_day||"X)" format(DailyTimeOn, 4, 2) "mins"
  285.  
  286.          mcounter = mcounter + 1
  287.          monthline.mcounter = month.old_m "("||format(signons_each_month,3)||"X)" format(MonthlyTimeOn, 5, 2) "mins"
  288.  
  289. /* -------------------------------------------------------------    */
  290.  
  291. /* Now output everything to console and to file        */
  292.  
  293. /* get the screen size; rows is what we are interested in    */
  294.  
  295. parse value SysTextScreenSize() with rows cols
  296.  
  297. call stream STDIN, C, "open read"
  298. /* Tell us all    */
  299.       intro = What_R_We
  300.       say intro
  301.       call lineout output_file, intro
  302.       intro = "Analysis of" log_file    "("||Date() "@" Time()||")"
  303.       say intro
  304.       call lineout output_file, intro
  305.       say crlf||DAILY TOTALS
  306.       call lineout output_file, crlf||DAILY TOTALS
  307.       do j = 1 to dcounter
  308.          say dayline.j
  309.          call lineout output_file, dayline.j
  310.          if one_screen_atatime = "YES" then            
  311.             if (j - rows + 6)//(rows - 5) = 0 then
  312.                do
  313.                   say "               Press any key to continue..."        
  314.                  answer = SysGetKey(NOECHO)
  315.                end
  316.       end
  317.  
  318.       if one_screen_atatime = "YES" then            
  319.           if (j - rows + 6)//(rows - 5) > 5 then     /* If at about 5 lines to        */
  320.                         /*a "Press-Any-Key to continue"...    */
  321.             do
  322.                say "   Daily Totals done, press any key for Monthlies..."        
  323.                answer = SysGetKey(NOECHO)
  324.                j = 0        /* If decision is to do a "Press-Any-Key to continue", reset to 0 */
  325.             end
  326.  
  327.       say crlf||MONTHLY TOTALS
  328.       call lineout output_file, crlf||MONTHLY TOTALS
  329.       do k = 1 to mcounter
  330.          say monthline.k
  331.          call lineout output_file, monthline.k
  332.          if one_screen_atatime = "YES" then            
  333.             if (k + j - rows + 6)//(rows - 6) = 0 then
  334.                do
  335.                   say "               Press any key to continue..."        
  336.                  answer = SysGetKey(NOECHO)
  337.                end
  338.       end
  339.    finished = crlf||"End of analysis of" log_file
  340.    say finished
  341.    call lineout output_file, finished
  342.  
  343. /* -------------------------------------------------------------------------------------------    */
  344.  
  345. /* Exit.  Also terminate VREXX if we are using it and if it has not already been removed */
  346.  
  347. CLEANUP:
  348.    if Use_VRexx = "YES" then call VExit
  349.  
  350.    exit