home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / lorautil.zip / LOG.CMD < prev    next >
OS/2 REXX Batch file  |  1995-05-08  |  16KB  |  451 lines

  1. /* LOG.CMD - REXX program to manage Lora's logfile, ver. 1.63
  2.   - 20 April, 1995 by Elliott Goodman, 1:102/1319 -
  3.  
  4. Donations for this program may be sent to:
  5.  
  6.      Elliott Goodman        
  7.      PO Box 500038          
  8.      Palmdale, CA 93591-0038
  9.  
  10. */
  11.  
  12. /* check whether RxFuncs are loaded. If not, load them. */       
  13.                                                                  
  14. if RxFuncQuery('SysLoadFuncs') then                              
  15. do                                                               
  16.         call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  17.         call SysLoadFuncs                                        
  18. end                                                              
  19.  
  20. path.1 = 'd:\lora'        /* set up directories */
  21. path.2 = 'd:\lora\lang'
  22.  
  23. /* call the date function and get a unique number based on it */
  24. day_index = SPECIFIED_DATE_IN_DAYS( DATE('U') )
  25. day_index = day_index - 1    /* if it's after midnight, when we are
  26.                 going to do our stuff, we want
  27.                 yesterday's date */
  28.  
  29. init_file = 'd:\lora\lang\init.log' /* file to initialize lora.zip */
  30. call SysFileDelete(init_file)            /* kill old file, if present */ 
  31.                                                                         
  32. m_txt = 'This is Lora.Zip'
  33. call lineout init_file, m_txt
  34.  
  35. call directory path.2        /* move to proper dir */
  36. old = 0                /* flag to indicate oldlora.zip exists */
  37.  
  38. call SysFileTree path.2||'\oldlora.zip', files, 'F'
  39. if files.0 \= 0 then
  40.   do
  41.     old = 1            /* if it exists, set flag */
  42.   end
  43.  
  44. /* all this is to get a month index for the current lora.zip file */
  45. call SysFileTree path.2||'\lora.zip', files, 'F'
  46. if files.0 = 0 then
  47.   do
  48.     'zip lora.zip init.log'
  49.   end
  50.   else
  51.   do
  52.       parse var files.1,
  53.          file_date,                  
  54.          file_time,                  
  55.          file_size,                  
  56.          file_attr,                  
  57.          file_name                   
  58.  
  59.     parse var file_date,
  60.       mm '/',
  61.       dd '/',
  62.       yy
  63.  
  64.     lora_zip_month = mm
  65.   end
  66.  
  67. /* set initial conditions: make sure a lora.log exists in the \lang subdir */
  68. call SysFileTree path.2||'\lora.log', files, 'F'
  69. if files.0 = 0 then 
  70.   do
  71.     'copy d:\lora\lora.log d:\lora\lang'
  72.     'del d:\lora\lora.log'
  73.     'exit'
  74.   end
  75.  
  76. /* this is an error condition that should never happen */
  77. if files.0 > 1 then
  78.   do
  79.     say 'More than one log file in d:\lora\lang'
  80.     'exit'
  81.   end
  82.  
  83. /* okay, files.0 = 1 (one lora.log file in \lora\lang exists)
  84. this is all to get the date of the file */
  85. do
  86.       parse var files.1,         /* log file in d:\lora\lang */
  87.          file_date,                  
  88.          file_time,                  
  89.          file_size,                  
  90.          file_attr,                  
  91.          file_name                   
  92.       file_name = STRIP( file_name ) 
  93.     lang_log = file_name
  94.     lang_date = file_date
  95.  
  96. /* now get the date of the current lora.log file in lora's subdir */
  97.     call SysFileTree path.1||'\lora.log', files, 'F'
  98.       parse var files.1,         /* log file in d:\lora */
  99.          file_date,                  
  100.          file_time,                  
  101.          file_size,                  
  102.          file_attr,                  
  103.          file_name                   
  104.       file_name = STRIP( file_name ) 
  105.     lora_log = file_name
  106.     lora_date = file_date
  107.  
  108. /* set a month index for the logfile for comparison with lora.zip */
  109.     parse var file_date,
  110.       mm '/',
  111.       dd '/',
  112.       yy
  113.  
  114.     lora_month = mm
  115.  
  116. /* if dates are equal, it's the same day so just append the log to
  117. the save log and erase the current one */
  118.       if lora_date = lang_date then
  119.     do
  120.         'cd \lora\lang'
  121.         'copy lora.log+d:\lora\lora.log lora.log'
  122.         'del d:\lora\lora.log'
  123.         'exit'
  124.     end
  125.  
  126. /* okay, dates are NOT equal. That means a new day has rolled by.
  127. First, now test if a new month has also passed. If so.... */
  128. if lora_month \= lora_zip_month then
  129.   do
  130. /* ...and we have an oldlora.zip file (a month's worth of logs)
  131. delete it and rename the current month's lora.zip to oldlora.zip */
  132.     if old = 1 then
  133.       do
  134.         'del d:\lora\lang\oldlora.zip'
  135.       end
  136.     'ren d:\lora\lang\lora.zip oldlora.zip'
  137.         call "d:\lora\lang\eom.cmd"
  138.  
  139. /* create a new lora.zip with a 20 byte nul file so we can
  140. move lora.logs into it without error */
  141.     'zip lora.zip init.log'
  142.   end
  143.  
  144. /* now, finally, create a unique name for yesterday's logfile and
  145. move it into our zip file. */    
  146.       'cd \lora\lang'
  147.  
  148.         say 'Door Tracker....'
  149.         call Door_tracker
  150.  
  151.         say "Running MSGCNT.CMD. Please wait...." 
  152.         call "d:\lora\lang\msgcnt.cmd"            
  153.  
  154.         say "Running CALLERS.CMD...."  
  155.         call "d:\lora\lang\callers.cmd"
  156.  
  157.         say 'Remove routine....'
  158.     call remove_stuff
  159.  
  160.         say 'Zipping....'
  161.       temp_name = day_index||'.log'
  162.       'ren d:\lora\lang\lora.log '||temp_name
  163.       'zip -m lora.zip '||temp_name
  164.  
  165. /* copy today's logfile into our storage area and delete the 
  166. current one */
  167.       'copy d:\lora\lora.log d:\lora\lang'
  168.       'del d:\lora\lora.log'
  169.       'exit'
  170. end
  171.  
  172. 'exit'
  173.  
  174. /* end of LOG.CMD */
  175.  
  176. /*------------------------------------------------*/  
  177. /* Convert calendar date to consistent date index            */  
  178. /*------------------------------------------------*/  
  179. SPECIFIED_DATE_IN_DAYS:                               
  180.    Procedure                                          
  181.                                                       
  182. parse arg,                                            
  183.    mm '/',                                            
  184.    dd '/',                                            
  185.    yy                                                 
  186.                                                       
  187. days_by_month = '31 28 31 30 31 30 31 31 30 31 30 31' 
  188. current_number_of_days = (yy * 365) + dd              
  189. do m = 1 while m < mm                                 
  190.    current_number_of_days = current_number_of_days +, 
  191.       WORD( days_by_month, m )                        
  192. end                                                   
  193. return current_number_of_days                         
  194. /* the above procedure was written by Dick Goran. I could come up
  195. with something that does the same thing but I like the way he does
  196. it so copied it. Doubt he'd mind since he posted it in a public echo! */
  197.  
  198. /*------------------------------------------------*/  
  199. /* removes lines from the log with certain key words         */
  200. /*------------------------------------------------*/  
  201. Remove_stuff:
  202.  
  203. /* we're in \lora\lang and we have one lora.log file there.
  204. we're going to move the file into the zip archive so this
  205. is only done once a day, just before the previous day's logfile
  206. is zipped. */
  207.  
  208. /* first, set up the phrases we DON'T want */
  209.  
  210. phrase. = ''
  211. phrase.1 = 'Reactivated'
  212. phrase.2 = 'Aka:'
  213. phrase.3 = 'Remote Uses'
  214. phrase.4 = 'Flags:'
  215. phrase.5 = 'Offer:'
  216. phrase.6 = 'Tranx:'
  217. phrase.7 = 'Remote clock:'
  218. phrase.8 = 'DL-Z/32'
  219. phrase.9 = 'STATS:'
  220. phrase.10 = 'sharing enabled'
  221. phrase.11 = '(GEcho)'
  222. phrase.12 = 'EMSI method:'
  223. phrase.13 = 'UL-Z/32'
  224. phrase.14 = 'Return code'
  225. phrase.15 = 'Building the outbound'
  226. phrase.16 = 'Nothing to send'
  227. phrase.17 = '(FMail)'
  228. phrase.18 = 'Type=2+'
  229. phrase.19 = 'Synchronizing'
  230. phrase.20 = 'Invoking'
  231. phrase.21 = 'Busy'
  232. phrase.22 = 'LWRD'
  233. phrase.23 = 'DEBUG:'
  234.  
  235. /* track # of successful finds */
  236. skip_line = 0
  237.  
  238. 'ren lora.log lora.bak'        /* save it, just in case */
  239. in_name = 'lora.bak'        /* set up work names */
  240. out_name = 'lora.log'
  241. do until lines(in_name) = 0        /* read in each line */
  242.   work_line = linein(in_name)        /* current line to examine */
  243.   found_phrase = 0            /* zero flag */
  244.   do i = 1 to 23            /* cycle thru phrases */
  245.   j = wordpos(phrase.i, work_line)    /* look for the phrase */
  246.   if j \= 0 then do            /* phrase found */
  247.       found_phrase = 1        /* set flag */
  248.       leave i                /* stop looking in this line */
  249.       end    /* end if j \= */
  250.   end        /* end do i */
  251.   if found_phrase = 1 then do        /* if found, don't write line */
  252.       skip_line = skip_line + 1
  253.       iterate                /* skip to next line */
  254.       end    /* end if found */
  255.   else do                /* phrase not found */
  256.       call lineout out_name, work_line    /* write line */
  257.       end    /* end else do */
  258. end        /* end do until */
  259. call lineout in_name            /* close files */
  260. call lineout out_name
  261. 'del lora.bak'            /* done with backup file */
  262.  
  263. /* display # of lines not written */
  264. say "Lines skipped:" skip_line
  265. Call SysSleep 5
  266.  
  267. return                /* continue processing lora.log */
  268.  
  269. /*------------------------------------------------*/  
  270. /* Door tracker - Tracks door usage                            */
  271. /*------------------------------------------------*/  
  272.  
  273. Door_tracker:  Procedure
  274.  
  275. phrase = 'External'                                                   
  276. phrase2 = 'Returned'
  277. phrase3 ='D:\LORA\LORD1.BAT'
  278. phrase4 = 'D:\LORA\DOORS\EZELS.BAT'
  279. phrase5 ='D:\LORA\PLANET1.BAT'
  280. phrase6 = 'Write'
  281. phrase7 = 'Connect FAX'
  282. phrase8 = 'Calls=1,'
  283. phrase9 = 'System call'
  284. phrase10 = 'Receiving' 
  285. phrase12 = 'D:\LORA\DOORS\EZVOTE\EZVOTE.BAT'
  286. phrase13 = 'D:\LORA\DOORS\SPIKE\SPIKE.BAT'  
  287.  
  288. count = 0                       /* count of times door is entered */
  289. ice = 0
  290. lord = 0                                                            
  291. planet = 0                                                          
  292. ezrom = 0                                                           
  293. ezvote = 0 
  294. spike = 0  
  295. fax_count = 0
  296. Sys_Txt = 'No System Calls??'
  297. BBS_calls = 0
  298. max_time = (24 * 3600)                                                
  299. total_time = 0                                                        
  300. save_file = 'd:\lora\lang\doors.txt'                                  
  301. total_hours = 0                                                       
  302. total_minutes = 0                                                     
  303. total_seconds = 0                                                     
  304.                                                                       
  305. m_txt = date('U')                                                     
  306. call lineout save_file, m_txt                                         
  307. m_txt = "--------"
  308. call lineout save_file, m_txt
  309.  
  310. in_name = 'lora.log'            /* set up work names */
  311.  
  312. do until lines(in_name) = 0             /* read in each line */
  313.   work_line = linein(in_name)           /* current line to examine */
  314.   j = wordpos(phrase, work_line)      /* look for the phrase */
  315.   if j \= 0 then do                     /* phrase found */
  316.       next_line = linein(in_name)
  317.       k = wordpos(phrase2, next_line)
  318.       if k \= 0 then do
  319. /* Okay, work_line has 'External' in it and next_line has 'Returned' in it.
  320. Therefore, a user has gone to a door and returned. Now, let's parse the lines */
  321.  
  322.         count = count + 1
  323. /* find out which door was run */                             
  324.                                                               
  325.         n = wordpos(phrase3, work_line) /* Test for Legend */ 
  326.           if n \= 0 then do                                   
  327.             lord = lord + 1                                   
  328.             end                                               
  329.                                                               
  330.         n = wordpos(phrase4, work_line) /* Test for EZ-Rom */
  331.           if n \= 0 then do                                   
  332.             ezrom = ezrom + 1                                 
  333.             end                                               
  334.                                                               
  335.         n = wordpos(phrase5, work_line) /* Test for Planets */
  336.           if n \= 0 then do                                   
  337.             planet = planet + 1                               
  338.             end                                               
  339.  
  340.         n = wordpos(phrase12, work_line)   /* Test for EZ-Vote */ 
  341.           if n \= 0 then do                                       
  342.             ezvote = ezvote + 1                                   
  343.             end                                                   
  344.                                                                   
  345.         n = wordpos(phrase13, work_line)  /* test for Spiked! */  
  346.           if n \= 0 then do                                       
  347.             spike = spike + 1                                     
  348.             end                                                   
  349.  
  350.         parse var work_line ':' start_time junk
  351.         parse var next_line ':' end_time junk
  352.         parse var start_time shour ':' smin ':' ssec
  353.         parse var end_time ehour ':' emin ':' esec
  354.         stotal = (3600 * shour) + (60 * smin) + ssec
  355.         etotal = (3600 * ehour) + (60 * emin) + esec
  356.         if stotal > etotal then
  357.           this_time = (max_time - stotal) + etotal
  358.         else
  359.           this_time = etotal - stotal
  360.         total_time = total_time + this_time
  361.  
  362.         end /* k \= */
  363.       k = wordpos(phrase6, next_line)
  364.       if k \= 0 then do
  365.     ice = ice + 1
  366.         count = count + 1
  367.       end /* if k \= 0 */     
  368.  
  369.    end       /* end if j \= */
  370.  
  371. /* check for a few other lines in the log */
  372.     else do                           
  373.  
  374. /* check for fax calls */
  375.       j = wordpos(phrase7, work_line) 
  376.       if j \= 0 then                  
  377.       do                              
  378.         fax_count = fax_count + 1     
  379.         end /* if j \= 0 */           
  380.  
  381. /* check for new callers. if found, announce in track file */
  382.       j = wordpos(phrase8, work_line)                              
  383.       if j \= 0 then                                               
  384.          do                                                        
  385.            parse upper var work_line . . first_name last_name 'OFF-LINE.' dummy
  386.            m_txt = "New caller: " first_name last_name
  387.            call lineout save_file, m_txt
  388.            end /* j \= 0 */
  389.  
  390. /* track high system call number */
  391.        j = wordpos(phrase9, work_line)
  392.        if j \= 0 then
  393.        do
  394.            parse var work_line . . Sys_Txt
  395.            BBS_calls = BBS_calls +1
  396.            end
  397.  
  398. /* monitor files received */
  399.         j = wordpos(phrase10, work_line)
  400.         if j \= 0 then
  401.         do
  402.             parse var work_line . . to_where dummy 
  403.             select                                           
  404.                when left(to_where, 13) = 'FILE\UNCHECK\' then do
  405.                   m_txt = 'File Uploaded:' to_where              
  406.                   call lineout save_file, m_txt
  407.                   end
  408.                otherwise                                     
  409.                   iterate                                    
  410.                end                                           
  411.             end
  412.  
  413.       end /* else j */
  414.  
  415. end             /* end do until */
  416. call lineout in_name                    /* close files */
  417.  
  418. /* save high system call number */
  419. m_txt = "BBS Calls:" BBS_calls || ", High" || Sys_Txt
  420. call lineout save_file, m_txt
  421.  
  422. if total_time > 3600 then do
  423.   total_hours = total_time % 3600
  424.   total_time = total_time // 3600
  425.   end
  426.  
  427. if total_time > 60 then do
  428.   total_minutes = total_time % 60
  429.   total_time = total_time // 60
  430.   end
  431.  
  432. total_seconds = total_time
  433.  
  434. /* change total to EXCLUDE Ice Edit */
  435. count = count - ice
  436.  
  437. m_txt = "Total times in doors yesterday =" count
  438. call lineout save_file, m_txt
  439. m_txt = "LORD =" lord "Planets =" planet "EZ-ELS =" ezrom "EZ-Vote =" ezvote "Spiked! =" spike
  440. call lineout save_file, m_txt
  441. m_txt = "Hours:" total_hours||", Minutes:" total_minutes
  442. call lineout save_file, m_txt
  443. m_txt = "Ice Edit wrote" ice "messages."
  444. call lineout save_file, m_txt
  445. /*  m_txt = "Faxes received: " fax_count
  446. call lineout save_file, m_txt */
  447. m_txt = "------------------------------"
  448. call lineout save_file, m_txt
  449.  
  450. return
  451.