//////////////////////////////////////////////////////////////////////////////// // // Task: OLDFILES.TSK // (Log files meeting a specific criteria for further processing.) // Author: Avanti Technology, Inc. // http://www.avanti-tech.com // Version: 1.0 - Initial Release // 1.1 - Updated to use DIR and other v4 enhancements // 1.2 - Updated date parsing logic // 1.3 - Add double quotes ("") to file spec to support // embedded spaces in non-DOS Name Space entries // // Description: // ============ // Search for and log files meeting a specific age criteria then delete them. // // Objective: // ========== // Automate File System cleanup. // // Usage: // ====== // Script can be manually executed using the TaskMaster TMRUN command // at the TMConsole (Shell) Screen: // // Example: TMRUN [vol:path\]OLDFILES.TSK // // Note: [vol:path\] is not required if the task resides either // in SYS:SYSTEM or the TaskMaster NLM load directory. // // Script can be scheduled for automatic execution using Client interface or // using the TaskMaster TMSCHEDULE command at the TMConsole (Shell) Screen: // // Examples: TMSCHEDULE ADD OLDFILES.TSK 01 02:00 // (Executes the 1st of each month at 2:00am) // // TMSCHEDULE ADD OLDFILES.TSK YNNNNNN 02:00 // (Executes every Sunday [SMTWTFS] at 2:00am) // // Note: Scheduled tasks must reside either in SYS:SYSTEM or the // TaskMaster NLM load directory for security reasons. // // Compatibility: // ============== // This task has been tested on the following platforms without demonstrating // any compatibility issues or any other reported/confirmed conflicts: // TaskMaster v4.05 (or later) // NetWare v4.1x / v5.x / v6.x // // Warning: // ======== // AS WITH ANY NEW SOFTWARE PROGRAM, BATCH SCRIPT, OR AUTOMATED PROCESSING // PROCEDURE, CAUTION SHOULD BE EXERCISED AND DUE DILIGENCE OBSERVED DURING // INITIAL IMPLEMENTATION. WHERE POSSIBLE, TESTING SHOULD BE PERFORMED ON // NON-PRODUCTION SYSTEMS PRIOR TO FULL IMPLEMENTATION. // //////////////////////////////////////////////////////////////////////////////// // Check for compatible version of TaskMaster NLM IF "%TM_VERSION%.%TM_SUBVERSION%%TM_REVISION%"<"4.05" // Report the status ECHO. ECHO Error: Incompatible TaskMaster release (requires v4.05 or later)! ECHO. ABORT ENDIF // Declare the task variables to be used VARALIAS %VAR10% %DIR_PATH% VARALIAS %VAR11% %DAYS_OLD% VARALIAS %VAR12% %DIR_DATE% // Define the contents of the task variables // (MODIFY) Definition which follows must be modified appropriately: // Starting directory for processing (do not include trailing separator '\') DEFINE %DIR_PATH% VOL:\PATH // (MODIFY) Definition which follows must be modified appropriately: // This example will process files using a 7 day criteria // To modify the criteria, change the 7 as appropriate // Note: Use 3 digit fixed length and zero filled format. DEFINE %DAYS_OLD% 7 // Reformat %DAYS_OLD% contents into 3 digit, zero filled, fixed length format REFORMAT %DAYS_OLD% 3 RIGHT REPLACE %DAYS_OLD% " 0" // Convert %DAYS_OLD% into appropriate Year and Day Of Year (1-365) IF "%DAYS_OLD%">="%NDAY_OF_YEAR%" // %DAYS_OLD% converts to a previous year CALC %3 (365 + %NDAY_OF_YEAR) - %DAYS_OLD% DEFINE %1 %YEAR%-=1 ELSE // %DAYS_OLD% is still within this year DEFINE %1 %YEAR% DEFINE %2 %NDAY_OF_YEAR%-=%DAYS_OLD% ENDIF // Define %DIR_DATE% as oldest date to retain (yyyymmdd - delete any previous) // (Convert calculated %YEAR% {%1} & %NDAY_OF_YEAR% {%2} to yyyymmdd) TOCALENDAR %DIR_DATE% %1%2 // Reformat %DIR_DATE% (yyyymmdd - TOCALENDAR output) into format required by // DIR /T= option (yyyy/mm/dd) PARSE %1 %DIR_DATE% 1-4 PARSE %2 %DIR_DATE% 5-6 PARSE %3 %DIR_DATE% 7-8 DEFINE %DIR_DATE% %1/%2/%3 // (MODIFY) The command which follows may be modified as appropriate: // File search and logging is easier/quicker using DIR due to new options in v4 // The default file specification in this .TSK is *.* which matches all files. // The different file specification can be changed (i.e., *.bak, *.tmp, etc.). // Process multiple file types by adding multiple DIR commands, using a specific // search pattern for each DIR, and appending >> to the log after the first DIR. // // Example: // // DIR %DIR_PATH%\*.bak /B /-D /S /T=M-%DIR_DATE% >%TASK_PATH%\%TASK_FILE%.DIR // (Using > creates/overwrites the log) // // DIR %DIR_PATH%\*.old /B /-D /S /T=M-%DIR_DATE% >>%TASK_PATH%\%TASK_FILE%.DIR // (Using >> appends to existing log) // // DIR %DIR_PATH%\*.tmp /B /-D /S /T=M-%DIR_DATE% >>%TASK_PATH%\%TASK_FILE%.DIR // (Using >> appends to existing log) // // // The following options are required: // // /B - Bare (name only, only includes full path if /S is used) // /-D - Directories excluded (list files only) // // // The following options can be used to narrow the matching files: // // /S - recurse subdirectories (i.e., process all dirs below) // Note: If /S removed, only %DIR_PATH% is processed. // // /T=A-%DIR_DATE% - Last Accessed on or before %3 (yyyy/mm/dd) // /T=C-%DIR_DATE% - Created on or before %3 (yyyy/mm/dd) // /T=M-%DIR_DATE% - Last Modified on or before %3 (yyyy/mm/dd) // Note: Only a single date option can be specified. // DIR %DIR_PATH%\*.* /B /-D /S /T=M-%DIR_DATE% >%TASK_PATH%\%TASK_FILE%.DIR OPEN READ %TASK_PATH%\%TASK_FILE%.DIR IF ERRORLEVEL OPEN WRITE %TASK_PATH%\%TASK_FILE%.ERR TRUNCATE IF NOT ERRORLEVEL WRITE ERROR: Unable to OPEN READ log - Check %TASK_PATH%\%TASK_FILE%.DIR CLOSE ENDIF ECHO. ECHO ERROR: Unable to OPEN READ log - Check %TASK_PATH%\%TASK_FILE%.DIR ECHO. EXIT ENDIF WHILE // Read the first/next record in the log READ %1 // ERRORLEVEL is set on End Of File (EOF) or ERROR IF ERRORLEVEL THEN BREAK // Get next record if last record read was null IF "%1"=="" THEN CONTINUE // Process the file // (MODIFY) The commands which follow may be modified as appropriate: // In this sample, the old files are deleted. // Innumerable other processing options exist. // First, FLAG the file to Normal attributes (i.e., reset Di and Ri, if set) FLAG "%1" N // Note: This format assumes the /S option was included. // If not (i.e., no /S option), use the following: // // FLAG "%DIR_PATH%\%1" N // // Double quotes ("") enclose the file specification // in case there are embedded spaces. // Next, DELETE the file DELETE "%1" // Note: This format assumes the /S option was included. // If not (i.e., no /S option), use the following: // // DELETE "%DIR_PATH%\%1" // // Double quotes ("") enclose the file specification // in case there are embedded spaces. LOOP // Close the redirected output log file CLOSE