home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ilog12.zip / ILOG.CMD < prev    next >
OS/2 REXX Batch file  |  1995-06-17  |  14KB  |  394 lines

  1. /*- REXX -ILOG.CMD V1.1 -------------------------------------------*
  2.  |                                                                 |
  3.  | Description:                                                    |
  4.  |                                                                 |
  5.  | This EXEC will summarize the total time you have been connected |
  6.  | to the Internet if you are using IBM (Advantis) as your Internet|
  7.  | provider.  The EXEC will attempt to get the path to the log     |
  8.  | dataset from the 'ETC' environment variable. Also, I'm assuming |
  9.  | that the name of the log dataset has not been changed from      |
  10.  | 'CONNECT.LOG'.  If it has, modify the code to point to the      |
  11.  | correct dataset (the full path is carried in the variable       |
  12.  | 'logfile').  Apparently the date format as output to the log has|
  13.  | been changed with the latest dialer update from MM/DD to        |
  14.  | YYYY/MM/DD. I've coded for this and this EXEC will handle both  |
  15.  | formats.                                                        |
  16.  |                                                                 |
  17.  | If you have any questions or comments, drop me a line at:       |
  18.  | 'ddarrow@ibm.net'.                                              |
  19.  |                                                                 |
  20.  | Date      Maintenance                           Who By          |
  21.  | --------  ------------------------------------  --------------  |
  22.  |                                                                 |
  23.  | 06/15/95  Author.                               Dempsey Darrow  |
  24.  |                                                                 |
  25.  | 06/17/95  Fixed problem where monthly totals    Dempsey Darrow  |
  26.  |           were not displayed when log                           |
  27.  |           did not span multiple months.                         |
  28.  |                                                                 |
  29.  *-----------------------------------------------------------------*/ ;
  30.  
  31. if   Found_Connect_Log()  /* The log was found */,
  32. then do ;
  33.         call Process_Connect_Log ;
  34.  
  35.         say yellow ;
  36.      end ;
  37. else do ;
  38.         say 'The search for ''CONNECT.LOG'' using the',
  39.             'environment variable ''ETC'' failed.' ;
  40.         say 'Try hard-coding the path and filename and then run',
  41.             'the program again.' ;
  42.      end ;
  43.  
  44. say ;
  45. say 'Press ENTER to terminate...' ;
  46.  
  47. pull x ;
  48.  
  49. exit ;
  50. /*======================== End of Main EXEC =======================*/ ;
  51. /*-  Section: Found_Connect_Log  ----------------------------------*
  52.  |                                                                 |
  53.  | This section will search for the path to the OS2 Internet       |
  54.  | Connection log dataset by examining the 'ETC' environment       |
  55.  | variable. We will assume that the log dataset name is still the |
  56.  | default: 'CONNECT.LOG'.                                         |
  57.  |                                                                 |
  58.  *-----------------------------------------------------------------*/ ;
  59.  
  60. Found_Connect_Log:
  61.  
  62. procedure expose logfile ;
  63.  
  64. Section_Rc = 1  /* Assume good result */ ;
  65.  
  66. File_Path = 'VALUE'(etc,,os2environment) ;
  67.  
  68. do 1 ;
  69.  
  70.    if   File_Path = ''  /* Variable doesn't exist */,
  71.    then do ;
  72.            Section_Rc = 0 ;
  73.  
  74.            leave ;
  75.         end ;
  76.    else logfile = File_Path'\connect.log' ;
  77.  
  78.    if   'STREAM'(logfile,'c','query size') = '',
  79.    then do ;
  80.            Section_Rc = 0 ;
  81.  
  82.            leave ;
  83.         end ;
  84.    else nop ;
  85.  
  86. end ;
  87.  
  88. return Section_Rc ;
  89. /*=================================================================*/ ;
  90. /*-  Section: Process_Connect_Log  --------------------------------*
  91.  |                                                                 |
  92.  | The log has been locate; process it.                            |
  93.  |                                                                 |
  94.  *-----------------------------------------------------------------*/ ;
  95.  
  96. Process_Connect_Log:
  97.  
  98. swidth = 78             /* Banner width             */ ;
  99. twidth = 66             /* Data   width             */ ;
  100.  
  101. "mode co80,25"          /* Set default display size */ ;
  102.  
  103. black  ='A'     /* Define ANSI colors       */ ;
  104. red    ='A'     /*                          */ ;
  105. green  ='A'     /*                          */ ;
  106. yellow ='A'     /*                          */ ;
  107. blue   ='A'     /*                          */ ;
  108.  
  109. call banner             /* Display header           */ ;
  110.  
  111. Accum_Hours    = 0 ;
  112. Accum_Minutes  = 0 ;
  113. Accum_Seconds  = 0 ;
  114. Total_Hours    = 0 ;
  115. Total_Minutes  = 0 ;
  116. Total_Seconds  = 0 ;
  117. Total_Sessions = 0 ;
  118.  
  119. count         = 0 ;
  120. Curr_Year     = '' ;
  121. Curr_Month    = '' ;
  122. spacer        = 'COPIES'(' ',12) ;
  123. Session_Count = 0 ;
  124.  
  125. do while 'LINES'(logfile) ;
  126.    parse value 'LINEIN'(logfile) with logdate logtime logtext ;
  127.  
  128.    if   'POS'('DISCONNECTED AFTER','TRANSLATE'(logtext)) = 0,
  129.    then nop ;
  130.    else call Process_Session ;
  131.  
  132. end ;
  133.  
  134. if   count = 0,
  135. then if   Session_Count = 0  /* Empty connect log */,
  136.      then nop ;
  137.      else do /* All log sessions within one month */ ;
  138.              Total_Sessions = Total_Sessions + Session_Count ;
  139.              count = count + 1 ;
  140.              data.count = logyear Word_Month(Curr_Month),
  141.                           'RIGHT'(Accum_Hours,2,'0')':',
  142.                        || 'RIGHT'(Accum_Minutes,2,'0')':',
  143.                        || 'RIGHT'(Accum_Seconds,2,'0'),
  144.                           'Sessions:' 'RIGHT'(Session_Count,5) ;
  145.           end ;
  146. else do         /* Pick up the final values */ ;
  147.         Total_Sessions = Total_Sessions + Session_Count ;
  148.         count = count + 1 ;
  149.         data.count = '    ' Word_Month(Curr_Month),
  150.                      'RIGHT'(Accum_Hours,2,'0')':',
  151.                   || 'RIGHT'(Accum_Minutes,2,'0')':',
  152.                   || 'RIGHT'(Accum_Seconds,2,'0'),
  153.                      'Sessions:' 'RIGHT'(Session_Count,5) ;
  154.      end ;
  155.  
  156. /* Close the log file */ ;
  157. call 'STREAM' logfile, 'C', 'CLOSE' ;
  158.  
  159. say black ;
  160.  
  161. /* Write out the summary */ ;
  162. do i = 1 to count by 1 ;
  163.    say 'CENTER'(spacer data.i,twidth) ;
  164. end i ;
  165.  
  166. say 'CENTER'('             ---------------------------------',twidth) ;
  167.  
  168. lline = spacer 'Total....' || 'RIGHT'(Total_Hours,2,'0')':',
  169.                            || 'RIGHT'(Total_Minutes,2,'0')':',
  170.                            || 'RIGHT'(Total_Seconds,2,'0'),
  171.                               'Sessions:' 'RIGHT'(Total_Sessions,5) ;
  172.  
  173. say red ;
  174. say 'CENTER'(lline,twidth) ;
  175. say blue ;
  176.  
  177. return ;
  178. /*=================================================================*/ ;
  179. /*-  Section: banner  ---------------------------------------------*
  180.  |                                                                 |
  181.  | Display the header.                                             |
  182.  |                                                                 |
  183.  *-----------------------------------------------------------------*/ ;
  184.  
  185. banner:
  186.  
  187. "echo on" ;
  188. "prompt $p$E[0;"34";"47";"4";"4"m]" ;
  189. "echo off" ;
  190. "cls" ;
  191.  
  192. frame1 = '+' || 'COPIES'('=',56) || '+' ;
  193. frame2 = '+' || 'COPIES'(' ',56) || '+' ;
  194. text   = '+ ILOG.CMD - V1.1 WARP Internet Connection Times Summary +' ;
  195.  
  196. say ;
  197. say 'CENTER'(frame1,swidth) ;
  198. say 'CENTER'(frame2,swidth) ;
  199. say 'CENTER'(text,swidth)   ;
  200. say 'CENTER'(frame2,swidth) ;
  201. say 'CENTER'(frame1,swidth) ;
  202. say ;
  203.  
  204. return ;
  205. /*=================================================================*/ ;
  206. /*-  Section: Process_Session  ------------------------------------*
  207.  |                                                                 |
  208.  | Process a session summary line.                                 |
  209.  |                                                                 |
  210.  *-----------------------------------------------------------------*/ ;
  211.  
  212. Process_Session:
  213.  
  214. procedure expose logdate logtime logtext data. count Curr_Year spacer,
  215.                  Curr_Month Accum_Hours Accum_Minutes Accum_Seconds,
  216.                  Total_Hours Total_Minutes Total_Seconds Session_Count,
  217.                  Total_Sessions logyear ;
  218.  
  219. if   'LENGTH'(logdate) = 5  /* Short date format */,
  220. then do ;
  221.         parse var logdate logmonth '/' logday ;
  222.  
  223.         logyear = 1995 ;
  224.      end ;
  225. else parse var logdate logyear '/' logmonth '/' logday ;
  226.  
  227. parse var logtext . . loghours ':' logminutes ':' logseconds . ;
  228.  
  229. if   Curr_Year = logyear,
  230. then if   Curr_Month = logmonth,
  231.      then do ;
  232.              Session_Count = Session_Count + 1 ;
  233.  
  234.              call Add_To_Current_Accumulators ;
  235.           end ;
  236.      else do ;
  237.              Total_Sessions = Total_Sessions + Session_Count ;
  238.              count = count + 1 ;
  239.  
  240.              if   count = 1,
  241.              then data.count = Curr_Year Word_Month(Curr_Month),
  242.                                'RIGHT'(Accum_Hours,2,'0')':',
  243.                             || 'RIGHT'(Accum_Minutes,2,'0')':',
  244.                             || 'RIGHT'(Accum_Seconds,2,'0'),
  245.                                'Sessions:' 'RIGHT'(Session_Count,5) ;
  246.              else data.count = '    ' Word_Month(Curr_Month),
  247.                                'RIGHT'(Accum_Hours,2,'0')':',
  248.                             || 'RIGHT'(Accum_Minutes,2,'0')':',
  249.                             || 'RIGHT'(Accum_Seconds,2,'0'),
  250.                                'Sessions:' 'RIGHT'(Session_Count,5) ;
  251.  
  252.              Curr_Month = logmonth ;
  253.  
  254.              Accum_Hours   = 0 ;
  255.              Accum_Minutes = 0 ;
  256.              Accum_Seconds = 0 ;
  257.              Session_Count = 1 ;
  258.  
  259.              call Add_To_Current_Accumulators ;
  260.           end ;
  261. else if   Curr_Year = '',
  262.      then do ;
  263.              Session_Count = Session_Count + 1 ;
  264.  
  265.              Curr_Year  = logyear ;
  266.              Curr_Month = logmonth ;
  267.  
  268.              call Add_To_Current_Accumulators ;
  269.           end ;
  270.      else do ;
  271.              Total_Sessions = Total_Sessions + Session_Count ;
  272.              count = count + 1 ;
  273.  
  274.              data.count = Curr_Year Word_Month(Curr_Month),
  275.                           'RIGHT'(Accum_Hours,2,'0')':',
  276.                        || 'RIGHT'(Accum_Minutes,2,'0')':',
  277.                        || 'RIGHT'(Accum_Seconds,2,'0')':' ;
  278.                           'Sessions:' 'RIGHT'(Session_Count,5) ;
  279.  
  280.              Accum_Hours   = 0 ;
  281.              Accum_Minutes = 0 ;
  282.              Accum_Seconds = 0 ;
  283.              Session_Count = 1 ;
  284.  
  285.              call Add_To_Current_Accumulators ;
  286.           end ;
  287.  
  288. return ;
  289. /*=================================================================*/ ;
  290. /*-  Section: Add_To_Current_Accumulators  ------------------------*
  291.  |                                                                 |
  292.  | Add session time to current year/month values.                  |
  293.  |                                                                 |
  294.  *-----------------------------------------------------------------*/ ;
  295.  
  296. Add_To_Current_Accumulators:
  297.  
  298. procedure expose Accum_Hours Accum_Minutes Accum_Seconds loghours,
  299.                  logminutes logseconds Total_Hours Total_Minutes,
  300.                  Total_Seconds ;
  301.  
  302. Accum_Seconds = Accum_Seconds + logseconds ;
  303.  
  304. if   Accum_Seconds > 59,
  305. then do ;
  306.         Accum_Seconds = Accum_Seconds - 60 ;
  307.         Accum_Minutes = Accum_Minutes + 1 ;
  308.  
  309.         if   Accum_Minutes > 59,
  310.         then do ;
  311.                 Accum_Minutes = Accum_Minutes - 60 ;
  312.                 Accum_Hours   = Accum_Hours + 1 ;
  313.              end ;
  314.         else nop ;
  315.  
  316.      end ;
  317. else nop ;
  318.  
  319. Accum_Minutes = Accum_Minutes + logminutes ;
  320.  
  321. if   Accum_Minutes > 59,
  322. then do ;
  323.         Accum_Minutes = Accum_Minutes - 60 ;
  324.         Accum_Hours   = Accum_Hours + 1 ;
  325.      end ;
  326. else nop ;
  327.  
  328. Accum_Hours = Accum_Hours + loghours ;
  329.  
  330. Total_Seconds = Total_Seconds + logseconds ;
  331.  
  332. if   Total_Seconds > 59,
  333. then do ;
  334.         Total_Seconds = Total_Seconds - 60 ;
  335.         Total_Minutes = Total_Minutes + 1 ;
  336.  
  337.         if   Total_Minutes > 59,
  338.         then do ;
  339.                 Total_Minutes = Total_Minutes - 60 ;
  340.                 Total_Hours   = Total_Hours + 1 ;
  341.              end ;
  342.         else nop ;
  343.  
  344.      end ;
  345. else nop ;
  346.  
  347. Total_Minutes = Total_Minutes + logminutes ;
  348.  
  349. if   Total_Minutes > 59,
  350. then do ;
  351.         Total_Minutes = Total_Minutes - 60 ;
  352.         Total_Hours   = Total_Hours + 1 ;
  353.      end ;
  354. else nop ;
  355.  
  356. Total_Hours = Total_Hours + loghours ;
  357.  
  358. return ;
  359. /*=================================================================*/ ;
  360. /*-  Section: Word_Month  -----------------------------------------*
  361.  |                                                                 |
  362.  | Convert numeric months to text.                                 |
  363.  |                                                                 |
  364.  *-----------------------------------------------------------------*/ ;
  365.  
  366. Word_Month:
  367.  
  368. procedure ;
  369.  
  370. arg nmonth ;
  371.  
  372. select ;
  373.  
  374.    when nmonth = 1  then tmonth = 'Jan' ;
  375.    when nmonth = 2  then tmonth = 'Feb' ;
  376.    when nmonth = 3  then tmonth = 'Mar' ;
  377.    when nmonth = 4  then tmonth = 'Apr' ;
  378.    when nmonth = 5  then tmonth = 'May' ;
  379.    when nmonth = 6  then tmonth = 'Jun' ;
  380.    when nmonth = 7  then tmonth = 'Jul' ;
  381.    when nmonth = 8  then tmonth = 'Aug' ;
  382.    when nmonth = 9  then tmonth = 'Sep' ;
  383.    when nmonth = 10 then tmonth = 'Oct' ;
  384.    when nmonth = 11 then tmonth = 'Nov' ;
  385.  
  386.    otherwise             tmonth = 'Dec' ;
  387.  
  388. end ;
  389.  
  390. return tmonth ;
  391. /*=================================================================*/ ;
  392.  
  393. /* End of EXEC */ ;
  394.