home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / UUPC11X3.ZIP / UUCLEAN.CMD < prev    next >
Encoding:
Text File  |  1992-12-01  |  11.6 KB  |  314 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 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.4 1992/12/01 04:35:12 ahd Exp $
  25.  *
  26.  *       $Log: UUCLEAN.CMD $
  27. *     Revision 1.4  1992/12/01  04:35:12  ahd
  28. *     Add new messages for processing status
  29. *
  30. *     Revision 1.3  1992/11/30  03:44:49  ahd
  31. *     Correct reset of deldir
  32. *
  33.  * Revision 1.2  1992/11/28  23:08:07  ahd
  34.  * Rewrite into REXX for OS/2
  35.  *
  36.  */
  37.  
  38. /*--------------------------------------------------------------------*/
  39. /*                    Trap uninitialized variables                    */
  40. /*--------------------------------------------------------------------*/
  41.  
  42. signal on novalue
  43. '@echo off'                   /* Do not echo command input           */
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*    To do anything, we need the name of the UUPC/extended spool     */
  47. /*    directory, configuration directory, and temporary directory     */
  48. /*--------------------------------------------------------------------*/
  49.  
  50. spooldir = getuupc("SPOOLDIR" )
  51. if spooldir == '' then
  52. do
  53.    say 'No spool directory defined, cannot continue'
  54.    exit 99
  55. end
  56.  
  57. confdir = getuupc("CONFDIR" )
  58. if confdir == '' then
  59. do
  60.    say 'No configuration directory defined, cannot continue'
  61.    exit 98
  62. end
  63.  
  64. tempdir = getuupc("TEMPDIR" )
  65. if tempdir == '' then
  66.    tempdir = value('TEMP',,'OS2ENVIRONMENT')
  67. if tempdir == '' then
  68.    tempdir = value('TMP',,'OS2ENVIRONMENT')
  69. if tempdir == '' then
  70. do
  71.    say 'No TEMP directory defined, cannot continue'
  72.    exit 98
  73. end
  74.  
  75. /*--------------------------------------------------------------------*/
  76. /*                    Disable UNDELETE processing                     */
  77. /*--------------------------------------------------------------------*/
  78.  
  79. deldir = value('DELDIR','','OS2ENVIRONMENT')
  80.  
  81. /*--------------------------------------------------------------------*/
  82. /*    Process odd logfiles which may have been left around by         */
  83. /*    aborted programs.                                               */
  84. /*--------------------------------------------------------------------*/
  85.  
  86. say 'Processing generic logs';
  87. call process spooldir,'UUPC*.LOG', 'GENERIC'
  88.  
  89. /*--------------------------------------------------------------------*/
  90. /*             SYSLOG has funny name, so process explictly            */
  91. /*--------------------------------------------------------------------*/
  92.  
  93. say 'Processing logs for SYSLOG';
  94. call process spooldir,'SYSLOG', 'SYSLOG'
  95.  
  96. /*--------------------------------------------------------------------*/
  97. /*                     Process all other log files                    */
  98. /*--------------------------------------------------------------------*/
  99.  
  100. xrc = SysFileTree(spooldir || '\*.log', 'data.','F')
  101. if xrc == 0 then
  102. do count = 1 to data.0
  103.    parse upper var data.count mmddyy hhmmss bytes attr fname
  104.    basename = filespec( 'N' , data.count )
  105.    parse var basename stem'.'
  106.    if left( basename, 4 ) <> 'UUPC' then   /* Don't do UUPC*.LOG again */
  107.    do;
  108.       say 'Processing logs for' basename;
  109.       call process spooldir, basename, stem
  110.    end
  111. end
  112.  
  113. /*--------------------------------------------------------------------*/
  114. /*           Clean up temporary files in the spool directory          */
  115. /*--------------------------------------------------------------------*/
  116.  
  117. call purge spooldir, '*.TMP'     /* Created by UUCICO                */
  118. call purge spooldir, '*.BAK'     /* Maybe created by UUCICO          */
  119.  
  120. /*--------------------------------------------------------------------*/
  121. /*         Clean up temporary files in the Temporary directory        */
  122. /*--------------------------------------------------------------------*/
  123.  
  124. call purge tempdir,'*.BAK'
  125. call purge tempdir,'UUPC*.TMP'
  126. call purge tempdir,'UUPC*.TXT'
  127.  
  128. /*--------------------------------------------------------------------*/
  129. /*             If the news ACTIVE file exists, run expire             */
  130. /*--------------------------------------------------------------------*/
  131.  
  132. if exist( confdir || '\active' ) then
  133.    'expire'
  134.  
  135. /*--------------------------------------------------------------------*/
  136. /*     Re-enable UNDELETE processing so we can clean up the cache     */
  137. /*--------------------------------------------------------------------*/
  138.  
  139. call value 'DELDIR',deldir,'OS2ENVIRONMENT'
  140.  
  141. /*--------------------------------------------------------------------*/
  142. /*    Purge the undelete cache to improve performance and free        */
  143. /*    space                                                           */
  144. /*--------------------------------------------------------------------*/
  145.  
  146. if deldir <> '' then
  147. do;
  148.    'UNDELETE /F /S /A' spooldir;
  149.    'UNDELETE /F /S /A' tempdir;
  150. end;
  151.  
  152. /*--------------------------------------------------------------------*/
  153. /*                           All done, exit                           */
  154. /*--------------------------------------------------------------------*/
  155.  
  156. return
  157.  
  158. /*--------------------------------------------------------------------*/
  159. /*    p r o c e s s                                                   */
  160. /*                                                                    */
  161. /*    Age a single set of log files                                   */
  162. /*--------------------------------------------------------------------*/
  163.  
  164. process:procedure
  165. parse upper arg spooldir, input, archive, maxsize, generation
  166. maxgen = 5
  167. aged   = 0                    /* Next older version was aged         */
  168. moved  = 0                    /* This version was aged               */
  169. if generation = '' then
  170.    generation = 1
  171. else
  172.    generation = generation + 1
  173.  
  174. if maxsize = '' then
  175. do;
  176.    if pos('*', input) > 0 then
  177.       maxsize = 0
  178.    else
  179.       maxsize = 10000;
  180. end;
  181. newgen = archive || '.' || right( generation, 3, '0')
  182. target = spooldir || '\' || newgen
  183.  
  184. if substr(target,2,1) = ':' then
  185.   target = substr( target, 3 );
  186.  
  187. /*--------------------------------------------------------------------*/
  188. /*          Determine if file exists  if not, return quietly          */
  189. /*--------------------------------------------------------------------*/
  190.  
  191. xrc = SysFileTree(spooldir || '\' || input , 'data.','F')
  192. if xrc <> 0 then
  193.    return 0
  194. /*--------------------------------------------------------------------*/
  195. /*             Process whatever files the search turned up            */
  196. /*--------------------------------------------------------------------*/
  197. do count = 1 to data.0
  198.    data = space(data.count)
  199.    parse upper var data mmddyy hhmmss bytes attr fname
  200.    if bytes = 0 then             /* Kill any empty file we find      */
  201.       call Purge fname
  202.    else if bytes > maxsize then
  203.    do
  204.  
  205.       if \ aged then             /* Only age olders file per run     */
  206.          aged = process(spooldir, newgen , archive, maxsize, generation)
  207.       say 'Aging' input 'to' target
  208.  
  209.       if generation > maxgen then      /* Really old files go away   */
  210.          call Purge fname
  211.       else if exist( target ) then     /* Else append if needed      */
  212.       do
  213.          'COPY' target || '+' || fname
  214.          call SysFileDelete fname
  215.       end
  216.       else
  217.          'MOVE' fname target     /* But move if possible, faster     */
  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.    xrc = sysfiledelete( fname )
  253.    if xrc == 0 then
  254.       say 'Deleted' fname
  255.    else
  256.       say 'Error deleting' fname || ', return code =' xrc
  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. /*       g e t u u p c                                                */
  275. /*                                                                    */
  276. /*       Get UUPC/extended configuration variable                     */
  277. /*--------------------------------------------------------------------*/
  278.  
  279. getuupc:procedure
  280. parse upper arg keyword,answer
  281.  
  282. uupcrc = value('UUPCSYSRC',,'OS2ENVIRONMENT')
  283. if  uupcrc == '' then
  284. do
  285.    'UUPCSYSRC not set, cannot continue'
  286.    exit 44
  287. end
  288.  
  289. xrc = SysFileSearch( keyword || '=',uupcrc,'data.')
  290. if xrc \= 0 then
  291. do
  292.    say 'SysFileSearch error' xrc 'searching' uupcrc 'for' keyword
  293.    exit xrc
  294. end
  295.  
  296. do count = 1 to data.0
  297.    parse var data.count newkey'='string
  298.  
  299.    if translate(newkey) = keyword then
  300.       answer = string
  301. end
  302. return translate(answer,'\','/')
  303.  
  304. /*--------------------------------------------------------------------*/
  305. /*    n o v a l u e                                                   */
  306. /*                                                                    */
  307. /*    Trap for uninitialized variables                                */
  308. /*--------------------------------------------------------------------*/
  309.  
  310. novalue:
  311. signal off novalue            /* Avoid nasty recursion         */
  312. say 'Uninitialized variable in line' sigl || ':'
  313. say sourceline( sigl )
  314.