home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / upc12b12.zip / uuclean.cmd < prev    next >
OS/2 REXX Batch file  |  1993-07-18  |  11KB  |  280 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       Program: UUCLEAN.CMD          28 Nov 1992                    */
  3. /*        Author: Andrew H. Derbyshire                                */
  4. /*                P.O. Box 132                                        */
  5. /*                Arlington, MA 01274                                 */
  6. /*      Internet: help@kew.com                                        */
  7. /*      Function: Perform automatic log file aging and purging        */
  8. /*                for UUPC/extended.                                  */
  9. /*      Language: REXX for OS/2 2.0                                   */
  10. /*     Arguments: None                                                */
  11. /*   Environment: OS/2 environment variable must be set to the        */
  12. /*                location of the UUPC/extended system                */
  13. /*                configuation file                                   */
  14. /*                (SET UUPCSYSRC=C:\UUPC\UUPC.RC)                     */
  15. /*--------------------------------------------------------------------*/
  16.  
  17. /*--------------------------------------------------------------------*/
  18. /*    Copyright (c) 1992-1993 by Kendra Electronic Wonderworks, all   */
  19. /*    rights reserved except those granted by the UUPC/extended       */
  20. /*    license.                                                        */
  21. /*--------------------------------------------------------------------*/
  22.  
  23. /*
  24.  *       $Id: uuclean.cmd 1.9 1993/07/19 02:53:49 ahd Exp $
  25.  *
  26.  *       $Log: uuclean.cmd $
  27.  *      Revision 1.9  1993/07/19  02:53:49  ahd
  28.  *      Correct aging of small files
  29.  *
  30.  *      Revision 1.8  1993/05/09  15:45:19  ahd
  31.  *      Don't age older generic log gratously
  32.  *      Age normal logs with 'p' suffix (generated by testing)
  33.  *      Up per file limit to 20000 bytes
  34.  *
  35.  *      Revision 1.7  1993/05/09  14:10:26  ahd
  36.  *      Don't perform undelete processing -- OS/2 bugs can cause crash!
  37.  *
  38. *     Revision 1.6  1993/04/04  05:01:49  ahd
  39. *     Use common getuupc.cmd for variable retrieval
  40. *
  41. *     Revision 1.5  1993/01/23  19:15:47  ahd
  42. *     Load required subroutine packages before using them
  43. *
  44. *     Revision 1.4  1992/12/01  04:35:12  ahd
  45. *     Add new messages for processing status
  46. *
  47. *     Revision 1.3  1992/11/30  03:44:49  ahd
  48. *     Correct reset of deldir
  49. *
  50.  * Revision 1.2  1992/11/28  23:08:07  ahd
  51.  * Rewrite into REXX for OS/2
  52.  *
  53.  */
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*                    Trap uninitialized variables                    */
  57. /*--------------------------------------------------------------------*/
  58. signal on novalue
  59. '@echo off'                   /* Do not echo command input           */
  60. Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  61. Call 'SysLoadFuncs'
  62.  
  63. /*--------------------------------------------------------------------*/
  64. /*    To do anything, we need the name of the UUPC/extended spool     */
  65. /*    directory, configuration directory, and temporary directory     */
  66. /*--------------------------------------------------------------------*/
  67.  
  68. spooldir = getuupc("SPOOLDIR" )
  69. if spooldir == '' then
  70. do
  71.    say 'No spool directory defined, cannot continue'
  72.    exit 99
  73. end
  74.  
  75. confdir = getuupc("CONFDIR" )
  76. if confdir == '' then
  77. do
  78.    say 'No configuration directory defined, cannot continue'
  79.    exit 98
  80. end
  81.  
  82. tempdir = getuupc("TEMPDIR" )
  83. if tempdir == '' then
  84. do
  85.    say 'No TEMP directory defined, cannot continue'
  86.    exit 98
  87. end
  88.  
  89. call setlocal;
  90. call value 'UUPCDEBUG','','OS2ENVIRONMENT';
  91. savedir = directory(spooldir)
  92.  
  93. /*--------------------------------------------------------------------*/
  94. /*    Process odd logfiles which may have been left around by         */
  95. /*    aborted programs.                                               */
  96. /*--------------------------------------------------------------------*/
  97.  
  98. say 'Processing generic logs';
  99. call process spooldir,'UUPC*.LOG', 'GENERIC',0
  100.  
  101. /*--------------------------------------------------------------------*/
  102. /*             SYSLOG has funny name, so process explictly            */
  103. /*--------------------------------------------------------------------*/
  104.  
  105. say 'Processing logs for SYSLOG';
  106. call process spooldir,'SYSLOG', 'SYSLOG'
  107.  
  108. /*--------------------------------------------------------------------*/
  109. /*                     Process all other log files                    */
  110. /*--------------------------------------------------------------------*/
  111.  
  112. xrc = SysFileTree(spooldir || '\*.log', 'data.','F')
  113.  
  114. if xrc == 0 then
  115. do count = 1 to data.0
  116.    parse upper var data.count mmddyy hhmmss bytes attr fname
  117.    basename = filespec( 'N' , data.count )
  118.    parse var basename stem'.'
  119.    if left( basename, 4 ) <> 'UUPC' then   /* Don't do UUPC*.LOG again */
  120.    do;
  121.       say 'Processing logs for' basename;
  122.       call process spooldir, stem || 'p.log', stem, 0
  123.       call process spooldir, basename, stem
  124.    end
  125. end
  126.  
  127. /*--------------------------------------------------------------------*/
  128. /*           Clean up temporary files in the spool directory          */
  129. /*--------------------------------------------------------------------*/
  130.  
  131. call purge spooldir, '*.TMP'     /* Created by UUCICO                */
  132. call purge spooldir, '*.BAK'     /* Maybe created by UUCICO          */
  133.  
  134. /*--------------------------------------------------------------------*/
  135. /*         Clean up temporary files in the Temporary directory        */
  136. /*--------------------------------------------------------------------*/
  137.  
  138. call purge tempdir,'*.BAK'
  139. call purge tempdir,'UUPC*.TMP'
  140. call purge tempdir,'UUPC*.TXT'
  141.  
  142. /*--------------------------------------------------------------------*/
  143. /*             If the news ACTIVE file exists, run expire             */
  144. /*--------------------------------------------------------------------*/
  145.  
  146. if exist( confdir || '\active' ) then
  147.    'expire'
  148.  
  149. /*--------------------------------------------------------------------*/
  150. /*                           All done, exit                           */
  151. /*--------------------------------------------------------------------*/
  152.  
  153. call directory savedir;
  154. return
  155.  
  156. /*--------------------------------------------------------------------*/
  157. /*    p r o c e s s                                                   */
  158. /*                                                                    */
  159. /*    Age a single set of log files                                   */
  160. /*--------------------------------------------------------------------*/
  161.  
  162. process:procedure
  163. parse upper arg spooldir, input, archive, maxsize, generation
  164. maxgen = 5
  165. aged   = 0                    /* Next older version was aged         */
  166. moved  = 0                    /* This version was aged               */
  167. defaultmax = 20000;           /* Max size of files                   */
  168. if generation = '' then
  169.    generation = 1
  170. else
  171.    generation = generation + 1
  172.  
  173. if maxsize = '' then
  174.    maxsize = defaultmax;
  175.  
  176. newgen = archive || '.' || right( generation, 3, '0')
  177. target = spooldir || '\' || newgen
  178.  
  179. /*--------------------------------------------------------------------*/
  180. /*          Determine if file exists  if not, return quietly          */
  181. /*--------------------------------------------------------------------*/
  182.  
  183. xrc = SysFileTree(spooldir || '\' || input , 'data.','F')
  184. if xrc <> 0 then
  185.    return 0
  186. /*--------------------------------------------------------------------*/
  187. /*             Process whatever files the search turned up            */
  188. /*--------------------------------------------------------------------*/
  189.  
  190. do count = 1 to data.0
  191.    data = space(data.count)
  192.    parse upper var data mmddyy hhmmss bytes attr fname
  193.    if bytes = 0 then             /* Kill any empty file we find      */
  194.       call Purge fname
  195.    else if bytes > maxsize then
  196.    do
  197.       if \ aged then             /* Only age older files per run     */
  198.          aged = process(spooldir, newgen , archive, defaultmax, generation)
  199.       say 'Aging' input 'to' target
  200.  
  201.       if generation > maxgen then      /* Really old files go away   */
  202.          call Purge fname
  203.       else if exist( target ) then     /* Else append if needed      */
  204.       do
  205.          'COPY' target || '+' || fname '/B'
  206.          call SysFileDelete fname
  207.       end
  208.       else do;
  209.          if substr(target,2,1) = ':' then
  210.             moveto = substr( target, 3 );
  211.          else
  212.             moveto = target
  213.          'MOVE' fname moveto     /* But move if possible, faster     */
  214.       end;
  215.       moved = 1
  216.    end
  217.  
  218. end count
  219.  
  220. /*--------------------------------------------------------------------*/
  221. /*       Flag whether or not files were moved to previous level       */
  222. /*--------------------------------------------------------------------*/
  223.  
  224. return moved
  225.  
  226. /*--------------------------------------------------------------------*/
  227. /*    p u r g e                                                       */
  228. /*                                                                    */
  229. /*    Delete files with specified mask and wildcard spec              */
  230. /*--------------------------------------------------------------------*/
  231.  
  232. purge:procedure
  233. parse arg directory,file
  234. if file == '' then
  235.    mask = directory
  236. else
  237.    mask = directory || '\' || file
  238. xrc = SysFileTree(mask, 'dir.', 'SF', '*----')
  239. if xrc <> 0 then
  240. do
  241.    say 'Directory read error' xrc
  242.    exit xrc
  243. end
  244. if dir.0 > 1 then
  245.    say dir.0 'files found for' mask
  246. do count = 1 to dir.0
  247.    parse var dir.count mmddyy hhmmss bytes attr fname
  248.    fname = space( fname )
  249.    xrc = sysfiledelete( fname )
  250.    if xrc == 0 then
  251.       say 'Deleted' fname
  252.    else
  253.       say 'Error deleting' fname || ', return code =' xrc
  254. end
  255. return
  256.  
  257. /*--------------------------------------------------------------------*/
  258. /*    e x i s t                                                       */
  259. /*                                                                    */
  260. /*    Report whether or not a file exists                             */
  261. /*--------------------------------------------------------------------*/
  262. exist: procedure
  263. parse arg file
  264. xrc = SysFileTree(file, 'data.','F')
  265. if data.0 == 0 then
  266.    return 0
  267. else
  268.    return 1
  269.  
  270. /*--------------------------------------------------------------------*/
  271. /*    n o v a l u e                                                   */
  272. /*                                                                    */
  273. /*    Trap for uninitialized variables                                */
  274. /*--------------------------------------------------------------------*/
  275.  
  276. novalue:
  277. signal off novalue            /* Avoid nasty recursion         */
  278. say 'Uninitialized variable in line' sigl || ':'
  279. say sourceline( sigl )
  280.