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