//////////////////////////////////////////////////////////////////////////////// // // Sample Task to delete a User's SYS:HOME directory after a specific // date. Useful for removing former employee directories after // sufficient time has elapsed for file recovery, etc. // //////////////////////////////////////////////////////////////////////////////// // // Files Used: // ----------- // HOME_DEL.LST (list of HOME directories and date to delete each) // HOME_DEL.BAK (backup of HOME_DEL.LST before last processing) // HOME_DEL.TMP (sorted HOME_DEL.LST temp file used in processing) // HOME_DEL.RPT (processing report) // // HOME_DEL.LST Data Format: // ------------------------- // Directory in HOME to delete (8 characters, space filled if shorter) // filler (2 characters, spaces) // Date to delete (8 characters in yyyymmdd numeric format, 19991231) // Example: // USERNAME 20001231 // (directory USERNAME on Dec. 31, 2000) // // Note: Use caution when editing the HOME_DEL.LST file and scheduling // this .TSK as DELTREE removes the files AND the directory which // typically makes file recovery (or salvage) impossible. // //////////////////////////////////////////////////////////////////////////////// // Check if the file containing the User information exists and EXIT if not IF NOT EXIST SYS:SYSTEM\HOME_DEL.LST THEN EXIT // Check if the interim (temporary sorted) file exists and delete it if exists IF EXIST SYS:SYSTEM\HOME_DEL.TMP THEN DELETE SYS:SYSTEM\HOME_DEL.TMP // SORT User information file (by date field then name field) to an interim file SORT SYS:SYSTEM\HOME_DEL.LST SYS:SYSTEM\HOME_DEL.TMP 11-18,1-8 // Check if the backup User information file exists and delete it if exists IF EXIST SYS:SYSTEM\HOME_DEL.BAK THEN DELETE SYS:SYSTEM\HOME_DEL.BAK // Rename the original User information file to a backup file RENAME SYS:SYSTEM\HOME_DEL.LST SYS:SYSTEM\HOME_DEL.BAK // OPEN the interim sorted file for READ input by this task OPEN_READ SYS:SYSTEM\HOME_DEL.TMP // OPEN the report file for WRITE output by this task (APPEND mode, no TRUNCATE) OPEN_WRITE SYS:SYSTEM\HOME_DEL.RPT // WRITE a header record to the report file WRITE Processing started: %MONTH%/%DAY%/%YEAR% @ %HOUR%:%MINUTE%%AM_PM% WRITE Removing User directories which expired on or before this date... // Main processing loop WHILE // READ the next record from the sorted User information file // IF ERRORLEVEL s TRUE then the End Of File (EOF) has been reached READ %9 IF ERRORLEVEL THEN BREAK // Check for a valid record (a NULL record indicates no more data in the file) IF "%9"=="" THEN BREAK // PARSE the User HOME directory field data into variable %1 PARSE %1 %9 1-8 // PARSE the date field data into variable %2 PARSE %2 %9 11-18 // Check if the parsed date field data is less than or equal to today's date IF %2<=%YEAR%%MONTH%%DAY% // Re-open the report file (APPEND mode, no TRUNCATE) for output OPEN_WRITE SYS:SYSTEM\HOME_DEL.RPT // Check if the specified User HOME directory exists // // IF it EXISTs, attempt to remove it using DELTREE, // checking the ERRORLEVEL to record the results. // // ELSE record that fact that it does not EXIST IF EXIST SYS:HOME\%1 DELTREE SYS:HOME\%1\*.* IF ERRORLEVEL WRITE *ERROR*: SYS:HOME\%1 removal failed ELSE WRITE SUCCESS: SYS:HOME\%1 removed ENDIF ELSE WRITE *ERROR*: SYS:HOME\%1 does not exist ENDIF ELSE // Re-open the User information file (APPEND mode, no TRUNCATE) for output // If the parsed date has not yet occurred, re-write the record to // the User information file for future processing OPEN_WRITE SYS:SYSTEM\HOME_DEL.LST WRITE %9 ENDIF LOOP // Re-open the report file (APPEND mode, no TRUNCATE) for output // and write a completion message OPEN_WRITE SYS:SYSTEM\HOME_DEL.RPT WRITE Processing complete: %MONTH%/%DAY%/%YEAR% @ %HOUR%:%MINUTE%%AM_PM% WRITE. // Close all OPEN_READ/OPEN_WRITE files CLOSE // Delete the interim (temporary sorted) User information // file used for processing IF EXIST SYS:SYSTEM\HOME_DEL.TMP THEN DELETE SYS:SYSTEM\HOME_DEL.TMP