home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / inettime.zip / INETTIME.CMD < prev    next >
OS/2 REXX Batch file  |  1998-01-28  |  18KB  |  363 lines

  1. /**************************************************************************/
  2. /*                                                                        */
  3. /* INETTIME.cmd - Procedure to summarize by month all connect time to the */
  4. /*                Internet using the IPDIALER.LOG as input data.          */
  5. /*                                                                        */
  6. /* Version:       2.0                                                     */
  7. /* Last Update:   January 28, 1998                                        */
  8. /*                                                                        */
  9. /* Copyright (c) D.A.Ritari-KNIGHT RESEARCH - 1995 - ALL RIGHTS RESERVED  */
  10. /*                                                                        */
  11. /* FREELY DISTRIBUTABLE FOR ANY USE OR PURPOSE.                           */
  12. /* NO WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PURPOSE IMPLIED.     */
  13. /*                                                                        */
  14. /*                                                                        */
  15. /* CONTACT:   Constructive comments and tips to:                          */
  16. /*                Internet:    dritari@ibm.net                            */
  17. /*                                                                        */
  18. /* FOR:       Warp Internet Users who want to know how much 'connect'     */
  19. /*            time they've used this month on IBM's Advantis Network.     */
  20. /*            (NOT for ALTERNATE-DIALER Users).                           */
  21. /*                                                                        */
  22. /* PURPOSE:   This small REXX program searches for the Internet connect   */
  23. /*            log on all available drives, and reads thru all the         */
  24. /*            entries in the log (in the file \mptn\etc\IPDIALER.LOG)     */
  25. /*            and SUMMARIZES the 'connect' time by month...quickly letting*/
  26. /*            you know how much time you've used this month. (I haven't   */
  27. /*            found a similar function with the Warp Internet bonus       */
  28. /*            pack apps). Assumptions are that you are using the SLIP     */
  29. /*            standard 'Dialer' app, that you have logging turned on,     */
  30. /*            and that the log file is set big enough to record more than */
  31. /*            a few connects. As this is a REXX application, you must     */
  32. /*            have REXX installed on your PC to run the program, and      */
  33. /*            if you prefer a PM-style application, it can be also run    */
  34. /*            using PMREXX. Testing of this app was minimal...if you      */
  35. /*            find that it doesn't run on your system, let me know or     */
  36. /*            modify it to your hearts content.                           */
  37. /*                                                                        */
  38. /*                                                                        */
  39. /* TO RUN:    At the 'C>' prompt:   INETTIME   (no parms needed)          */
  40. /*            At the 'C>' prompt:   INETTIME C:\mydir\IPDIALER.LOG        */
  41. /*            or for PMREXX usage:  PMREXX INETTIME.CMD                   */
  42. /*                                                                        */
  43. /*                                                                        */
  44. /* UPDATES:   Version 1.0 - Original Release - January 25, 1995           */
  45. /*            Version 1.1 - Inadvertently left off last entry in log.     */
  46. /*                          This corrected original error.                */
  47. /*            Version 1.2 - Variety of fixes for 'connect.log' files      */
  48. /*                          which have missing carriage returns, spliced  */
  49. /*                          lines, broken lines etc., which caused the    */
  50. /*                          calculations to abend. Also, added better     */
  51. /*                          lookup of where connect.log exists by using   */
  52. /*                          the environment 'ETC' parm if it exists.      */
  53. /*            Version 1.3 - Added new YEAR information added to log       */
  54. /*                          entries available with DIALER version 1.45.   */
  55. /*                          Also, Dialer-1.45 LOCKS the CONNECT.LOG file  */
  56. /*                          and keeps it locked, even after you hangup.   */
  57. /*                          An error message was added advising you to    */
  58. /*                          close the Dialer app before running INETTIME. */
  59. /*            Version 2.0 - Changed default name of logfile for the newer */
  60. /*            JAN/1998      IBM Dialer - 1.69 or greater...IPDIALER.LOG   */
  61. /*                          (was CONNECT.LOG). Changed search directory   */
  62. /*                          to \mptn\etc from \tcpip\etc directory. Fixed */
  63. /*                          date error in December...always showed the    */
  64. /*                          new year instead of the old year (Thanks      */
  65. /*                          Tom for the error report). IF you are still   */
  66. /*                          using the old dialer, either rename the log   */
  67. /*                          in the dialer setup to IPDIALER.LOG or change */
  68. /*                          the source code at the start of the program   */
  69. /*                          in the LOGNAME entry...remarked statement     */
  70. /*                          already provided, or override the name of the */
  71. /*                          log by running INETTIME with the fulle path...*/
  72. /*                              INETTIME C:\mptn\etc\connect.log          */
  73. /*                                                                        */
  74. /* PROBLEMS:  Do not use this program if you ONLY use the Alternate       */
  75. /*            Dialer (AD). The AD does NOT produce a IPDIALER.LOG to      */
  76. /*            summarize (INETTIME won't be able to find the log).         */
  77. /*                                                                        */
  78. /*            If INETTIME reports that it can't find your IPDIALER.LOG    */
  79. /*            file OR you have MULTIPLE ipdialer.log files and you don't  */
  80. /*            want a report on the first one it finds, specify the name   */
  81. /*            of the log on the command line when you run the program...  */
  82. /*                INETTIME   R:\example\other\backup\IPDIALER.LOG         */
  83. /*            for example (or whereever you keep you IPDIALER.LOG file).  */
  84. /*                                                                        */
  85. /*            If the INETTIME report has a month with '???' in it, your   */
  86. /*            IPDIALER.log file is corrupted on one or more entries.      */
  87. /*            A normal log entries looks like the following line:         */
  88. /*                                                                        */
  89. /*    12/11 17:22:37 Disconnected after 01:14:01  0 errors  0 discards    */
  90. /*                                                                        */
  91. /*            A corrupted line might look like the following:             */
  92. /*                                                                        */
  93. /*    xxxxx 17:22:37 Disconnected af                                      */
  94. /*    ter 01:14:01  0 errors  0 discards                                  */
  95. /*                                                                        */
  96. /*            As you can see, the log entry has (somehow) gotten split    */
  97. /*            into two lines...INETTIME will find the 'Disconnected'      */
  98. /*            line BUT there is no time to report and the date field      */
  99. /*            contains X's...the program will not abend...will attempt    */
  100. /*            to summarize the data on a '???' month and continues.       */
  101. /*            If you can edit the ipdialer.log file and straight out      */
  102. /*            the entries, future reports will summarize correctly.       */
  103. /*            (See caution below on editing the log).                     */
  104. /*                                                                        */
  105. /* LOG SIZE:  In the Dialer, I strongly suggest that you set IPDIALER.LOG */
  106. /*            size to an amount LARGER THAN 10K...I suggest at least      */
  107. /*            50K for 6 months of log activity. Also, I edit the log      */
  108. /*            occasionally to remove old month's activities (instead of   */
  109. /*            just letting the dialer arbitrarily 'trim' back your log).  */
  110. /*            (See caution below on editing the log).                     */
  111. /*                                                                        */
  112. /* CAUTIONS:  Do not edit your IPDIALER.LOG file with an ASCII editor     */
  113. /*            which puts an END-OF-FILE (EOF) mark at the end of the      */
  114. /*            file! The IBM dialer program will write log entries AFTER   */
  115. /*            this mark and you will not be able to see new log entries   */
  116. /*            using INETTIME or other ASCII-based programs (or just       */
  117. /*            'TYPE ipdialer.log') in the future. Either remove the EOF   */
  118. /*            character or erase the log and let the dialer build you     */
  119. /*            a new one for future use...A remove-end-of-file-mark        */
  120. /*            program has been included for this purpose...See REMOVEOF.  */
  121. /*                                                                        */
  122. /**************************************************************************/
  123.  
  124. PARSE ARG connect_log_in
  125.  
  126.  /*** IF YOU ARE USING IBM's DIALER PROGRAM 1.69 or greater *******************/
  127.      LOGNAME = "IPDIALER.LOG"          /* IBM's Dialer 1.69 or greater        */
  128.  /*** IF YOU ARE USING AN OLDER VERSION OF IBM's DIALER PROGRAM < 1.69        */
  129.      /*** LOGNAME = "CONNECT.LOG" ***/ /* Dialer BEFORE 1.69 used this name   */
  130.  
  131.  
  132.  if connect_log_in \== "" then do  /* User specified log name on cmd line */
  133.      logfile = connect_log_in
  134.      if "" == stream(logfile, 'c', 'query exists') then do
  135.          say " "
  136.          say "Can't find file: " logfile
  137.          say "Procedure Canceled."
  138.          say " "
  139.          exit 1
  140.          END
  141.      END
  142.  else do
  143.      call P_FindConnectLog         /* Search for the ipdialer.log file */
  144.      END
  145.  
  146.  call P_InitMonthTable
  147.  call P_InitMonthNames
  148.  call P_DisplayHeading
  149.  
  150.  
  151.  /*------------------- Loop through all records in Log file. -------------*/
  152.  
  153.  PMonth = 0
  154.  PYear  = 0
  155.  year_hold = 0
  156.  do while LINES(logfile) > 0
  157.      currline = LINEIN(logfile)
  158.      parse VAR   currline first     currline2
  159.      parse VAR   currline2 second   currline2
  160.      parse VAR   currline2 third    currline2
  161.      parse VAR   currline2 fourth   currline2
  162.      parse VAR   currline2 fifth    currline2
  163.      if third == "Disconnected" then do         /* Use only DISCONNECT lines */
  164.          /* Validate first argument before using - added in version 1.2 */
  165.          first_length = LENGTH(first);
  166.  
  167.  
  168.          /* Possible YYYY/MM/DD format added in Dialer version 1.45 */
  169.          /* If possible YYYY, get YEAR - added in version 1.3       */
  170.          if first_length > 5 then do
  171.              month_hold = RIGHT(first, 5, '0');
  172.              year_hold  = substr(first, 1, 4);
  173.              first = month_hold;
  174.              if DATATYPE(year_hold, 'N') \== 1 then year_hold = 0;
  175.              END
  176.          month = substr(first, 1, 2)
  177.          month = STRIP(month,'L',0)
  178.          /* verify that 'month' is NUMERIC - added in version 1.2 */
  179.          if DATATYPE(month, 'N') \== 1 then month = 13;
  180.  
  181.          if  month \== PMonth then do
  182.              if PMonth \== 0 then do
  183.                  call P_DisplayDetail           /* Month break - summarize */
  184.                  call P_InitMonthTable
  185.                  PMonth = month
  186.                  Pyear  = year_hold
  187.                  end
  188.              else do
  189.                  PMonth = month
  190.                  Pyear  = year_hold
  191.                  end
  192.              end
  193.  
  194.          connects.month = connects.month + 1
  195.          parse VALUE fifth WITH hours ':' minutes ':' seconds
  196.          /* Validate hours, minutes, seconds before using - added in 1.2 */
  197.          if DATATYPE(hours, 'N') \== 1 then hours = 0;
  198.          if DATATYPE(minutes, 'N') \== 1 then minutes = 0;
  199.          if DATATYPE(seconds, 'N') \== 1 then seconds = 0;
  200.  
  201.          if seconds > 0 then do
  202.              seconds = 0
  203.              minutes = minutes + 1
  204.              if minutes > 59 then do
  205.                  minutes = 0
  206.                  hours = hours + 1
  207.                  end
  208.              end
  209.          totalhours.month   = totalhours.month + hours
  210.          totalminutes.month = totalminutes.month + minutes
  211.          end
  212.      end
  213.  
  214.  ok = stream(logfile, 'C', 'CLOSE')
  215.  
  216.  call P_DisplayDetail                           /* Display final month */
  217.  say ' '
  218.  
  219.  exit 0
  220.  
  221. /***************************************************************************
  222. Procedure Name: P_DisplayHeading
  223. ****************************************************************************/
  224. P_DisplayHeading:
  225.  
  226.  head = "Log:" logfile
  227.  headlen = LENGTH(head)
  228.  if headlen < 52 then headlen = 52;
  229.  if headlen > 78 then headlen = 78;
  230.  
  231.  say " "
  232.  say "+--" || CENTER("", headlen, '-') || "--+"
  233.  say "+"  CENTER("IBM Global Network - Internet Connection Summary", headlen) "  +"
  234.  say "+"  CENTER("INETTIME - Version: 2.0", headlen) "  +"
  235.  temp1 = date('U') time()
  236.  say "+"  CENTER(temp1, headlen) "  +"
  237.  say "+"  CENTER(head, headlen) "  +"
  238.  say "+--" || CENTER("", headlen, '-') || "--+"
  239.  say " "
  240.  return
  241.  
  242. /***************************************************************************
  243. Procedure Name: P_DisplayDetail
  244. ****************************************************************************/
  245. P_DisplayDetail:
  246.  do while totalminutes.PMonth > 59
  247.      totalhours.PMonth = totalhours.PMonth + 1
  248.      totalminutes.PMonth = totalminutes.PMonth - 60
  249.      end
  250.  if totalhours.PMonth \== 0 | totalminutes.PMonth \== 0 then do
  251.      if PYear == 0 then do
  252.          say  '    ' ||,
  253.               COPIES(' ', ((headlen - 52) % 2)),
  254.               monthname.PMonth ,
  255.               FORMAT(totalhours.PMonth, 3),
  256.               'Hrs.',
  257.               FORMAT(totalminutes.PMonth,2),
  258.               'Min. -',
  259.               FORMAT(connects.PMonth, 3),
  260.               'Sessions -' ||,
  261.               FORMAT((((totalhours.PMonth * 60) + totalminutes.PMonth) / connects.PMonth),4,0),
  262.               'Min. Avg.'
  263.          end
  264.      else do
  265.          say  PYear ||,
  266.               COPIES(' ', ((headlen - 52) % 2)),
  267.               monthname.PMonth ,
  268.               FORMAT(totalhours.PMonth, 3),
  269.               'Hrs.',
  270.               FORMAT(totalminutes.PMonth,2),
  271.               'Min. -',
  272.               FORMAT(connects.PMonth, 3),
  273.               'Sessions -' ||,
  274.               FORMAT((((totalhours.PMonth * 60) + totalminutes.PMonth) / connects.PMonth),4,0),
  275.               'Min. Avg.'
  276.          end
  277.      end
  278.  return
  279.  
  280. /***************************************************************************
  281. Procedure Name: P_InitMonthTable
  282. ****************************************************************************/
  283. P_InitMonthTable:
  284.  
  285.  temp = 13
  286.  do while temp >= 0
  287.      totalhours.temp   = 0
  288.      totalminutes.temp = 0
  289.      connects.temp     = 0
  290.      temp = temp - 1
  291.      end
  292.  return
  293.  
  294.  
  295. /***************************************************************************
  296. Procedure Name: P_InitMonthNames
  297. ****************************************************************************/
  298. P_InitMonthNames:
  299.  
  300.  monthname.0  = '???:'
  301.  monthname.1  = 'JAN:'
  302.  monthname.2  = 'FEB:'
  303.  monthname.3  = 'MAR:'
  304.  monthname.4  = 'APR:'
  305.  monthname.5  = 'MAY:'
  306.  monthname.6  = 'JUN:'
  307.  monthname.7  = 'JUL:'
  308.  monthname.8  = 'AUG:'
  309.  monthname.9  = 'SEP:'
  310.  monthname.10 = 'OCT:'
  311.  monthname.11 = 'NOV:'
  312.  monthname.12 = 'DEC:'
  313.  monthname.13 = '???:'
  314.  return
  315.  
  316.  
  317. /***************************************************************************
  318. Procedure Name: P_FindConnectLog
  319. ****************************************************************************/
  320. P_FindConnectLog:
  321.  
  322.  /*** Try finding IPDIALER.LOG first using the ETC environment variable   ***/
  323.  LogPath = value(ETC,,OS2ENVIRONMENT);
  324.  temp_path = REVERSE(LogPath);
  325.  if '\' == substr(temp_path, 1, 1) then
  326.      logfile = LogPath || LOGNAME;
  327.  else
  328.      logfile = LogPath || '\' || LOGNAME;
  329.  
  330.  if "" == stream(logfile, 'c', 'query exists') then do
  331.      /*** Find where the IPDIALER.LOG file is (check C,D,E,F...Z drives)  ***/
  332.      LogPath = ':\mptn\etc\' || LOGNAME;
  333.      DO i = 67 to 90 BY 1      /* Drive C --> Drive Z */
  334.          if "" \== stream(D2C(i) || LogPath,'c','query exists') then DO
  335.              logfile = D2C(i) || LogPath;
  336.              LEAVE;
  337.              END
  338.          END
  339.      END
  340.  
  341.  if "" == stream(logfile, 'c', 'query exists') then do
  342.      say " "
  343.      say "'ETC' variable doesn't point to IPDIALER.LOG in the environment!"
  344.      say "Can't find \mptn\etc\IPDIALER.LOG on Drives C thru Z!"
  345.      say "No filename argument passed for the IPDIALER.LOG location!"
  346.      say "(This program does not summarize time for the Alternate-Dialer)."
  347.      say "Procedure Canceled."
  348.      say " "
  349.      EXIT 1
  350.      END
  351.  
  352.  if "READY:" \== stream(logfile, 'c', 'open read') then do
  353.      say " "
  354.      say "INETTIME - Version: 2.0 - ERROR opening IPDIALER.LOG!"
  355.      say "  The IPDIALER.LOG file is probably LOCKED! Please exit the DIALER"
  356.      say "  application to unlock the file...then rerun INETTIME."
  357.      say " "
  358.      EXIT 2
  359.      END
  360.  
  361.  
  362.  return
  363.