home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / timevent / taskmstr / del_temp.tsk < prev    next >
Encoding:
Text File  |  1995-05-07  |  4.1 KB  |  206 lines

  1. /////////////////////////////////////////////////////////////////////
  2. // This Task file searches for .BAK & .TMP files which can be deleted
  3. // so as to make more Volume space available.  It could be spawned by
  4. // any number of network monitoring packages in response to a Volume/
  5. // Disk space at threshold alert.
  6. /////////////////////////////////////////////////////////////////////
  7.  
  8.  
  9. // Open an output file to log what action is taken
  10.  
  11. OPEN_WRITE SYS:SYSTEM\PURGE.DAT
  12.  
  13.  
  14. // Write a null line to separate previous entries
  15.  
  16. WRITE
  17.  
  18.  
  19. // Echo and Write a header identifying this action
  20.  
  21. ECHO_WRITE %TASK_NAME% started on %MONTH%/%DAY%/%YEAR% at %HOUR%:%MINUTE%%AM_PM%
  22.  
  23.  
  24. // Variables used:
  25. //
  26. //   %0 : Directory search starting point
  27. //   %1 : Next matching directory in search
  28. //   %2 : Next matching file in search
  29. //   %9 : Original Working Directory
  30.  
  31.  
  32. // Save the Current Working Directory (CWD)
  33.  
  34. DEFINE %9 %CWD%
  35.  
  36.  
  37. // Set %1 to 'nul' (an invalid return from %DIR_TREE_%) 
  38. // to isolate the first pass of the %DIR_TREE_% request.
  39.  
  40. DEFINE %1 nul
  41.  
  42.  
  43. // Set %0 to the starting point to begin traversing
  44.  
  45. DEFINE %0 SYS:\
  46.  
  47.  
  48. // Set the Current Working Directory (CWD) to the
  49. // starting point for the directory tree traversing
  50.  
  51. CD %0
  52.  
  53.  
  54. // Directory traversing uses this WHILE/LOOP
  55.  
  56. WHILE "%1">""
  57.  
  58.  
  59.   // Check if any .BAK files exist in this directory
  60.  
  61.   IF EXIST *.BAK
  62.  
  63.  
  64.     // Define variable %2 as the first matching
  65.     // file in the search
  66.  
  67.     DEFINE %2 %DIR_FILE_*.BAK%
  68.  
  69.  
  70.     // For file checking, uses a WHILE/LOOP which
  71.     // loops while %2 is defined
  72.  
  73.     WHILE "%2">""
  74.  
  75.  
  76.       // Check if this file has been accessed today
  77.       // %FILE_ACCESS_% format = (yyyy/mm/dd)
  78.  
  79.       IF "%FILE_ACCESS_%2%"<"%YEAR%/%MONTH%/%DAY%"
  80.  
  81.  
  82.         // Echo/Write a message on what we're about to do
  83.  
  84.         ECHO_WRITE %CWD%\%2 (Owner: %FILE_OWNER_%2%) deleted!
  85.  
  86.  
  87.         // It has not been accessed today so
  88.         // First we'll FLAG it RW -DI -RI...
  89.  
  90.         FLAG %2 rw
  91.  
  92.  
  93.         // Then we'll delete it!
  94.  
  95.         DEL %2
  96.  
  97.  
  98.       // End of %FILE_ACCESS_% check structure
  99.  
  100.       ENDIF
  101.  
  102.  
  103.       // Get the next matching file
  104.  
  105.       DEFINE %2 %DIR_FILE_%
  106.  
  107.  
  108.     // Repeat the process
  109.  
  110.     LOOP
  111.  
  112.  
  113.   // End of IF EXIST *.BAK structure
  114.  
  115.   ENDIF
  116.  
  117.  
  118.   // Check if any .TMP files exist in this directory
  119.  
  120.   IF EXIST *.TMP
  121.  
  122.  
  123.     // Define variable %2 as the first matching
  124.     // file in the search
  125.  
  126.     DEFINE %2 %DIR_FILE_*.TMP%
  127.  
  128.  
  129.     // For file checking, uses a WHILE/LOOP which
  130.     // loops while %2 is defined
  131.  
  132.     WHILE "%2">""
  133.  
  134.  
  135.       // Check if this file has been accessed today
  136.       // %FILE_ACCESS_% format = (yyyy/mm/dd)
  137.  
  138.       IF "%FILE_ACCESS_%2%"<"%YEAR%/%MONTH%/%DAY%"
  139.  
  140.  
  141.         // Echo/Write a message on what we're about to do
  142.  
  143.         ECHO_WRITE %CWD%\%2 (Owner: %FILE_OWNER_%2%) deleted!
  144.  
  145.  
  146.         // It has not been accessed today so
  147.         // First we'll FLAG it RW -DI -RI...
  148.  
  149.         FLAG %2 rw
  150.  
  151.  
  152.         // Then we'll delete it!
  153.  
  154.         DEL %2
  155.  
  156.  
  157.       // End of %FILE_ACCESS_% check structure
  158.  
  159.       ENDIF
  160.  
  161.  
  162.       // Get the next matching file
  163.  
  164.       DEFINE %2 %DIR_FILE_%
  165.  
  166.  
  167.     // Repeat the process
  168.  
  169.     LOOP
  170.  
  171.  
  172.   // End of IF EXIST *.TMP structure
  173.  
  174.   ENDIF
  175.  
  176.  
  177.   // Define variable %1 as the next matching entry in the
  178.   // directory tree as it is traversed by %DIR_TREE_%.  If
  179.   // this is the first directory checked, %1 will be null.
  180.   // Therefore, we must provide a starting point for the
  181.   // %DIR_TREE_% System Environment variable to work from
  182.   // (Note: %0 was previously defined as the search starting
  183.   // point and is used so that it only need be defined once.)
  184.  
  185.   IF "%1"=="nul"
  186.     DEFINE %1 %DIR_TREE_%0%
  187.   ELSE
  188.     DEFINE %1 %DIR_TREE_%
  189.   ENDIF
  190.  
  191.  
  192. // LOOP back up to the WHILE check for the next directory tree level
  193.  
  194. LOOP
  195.  
  196.  
  197. // Return to the saved original directory
  198.  
  199. CD %9
  200.  
  201.  
  202. // Close the output file (not required since TaskMaster will
  203. // cleanup after a Task but shows good design and structure)
  204.  
  205. CLOSE
  206.