//============================================================================= // // Task: LOGTYPES.TSK // (Locate/log/report files of specific names/types/extensions) // Author: Avanti Technology, Inc. // http://www.avanti-tech.com // Version: 1.0 - Release [11 Nov 2003] Initial version // 1.1 - Updated [19 Dec 2003] Check for name(s), as well as ext(s) // // Description: // ============ // Generate a log of specific file types (based upon name or ext) then parse // that information to create a log file (report) providing the following: // - Total Count for each file type located // - Total Disk Space Used by each file type // - Size of and Path to each file grouped by file type // // System Environment Variables (%0 - %9) needing task specific definition: // ------------------------------------------------------------------------ // %0 Base directory to search from (set by DEFINE) // %1 Base path/file (no .ext) for files (set by DEFINE) // // The internal System Environment Variables are used to simplify processing // and maintenance on the script. For example, using %0 in place of the base // pattern allows us to easily change the base pattern throughout the task // merely by changing the DEFINE which sets its value. // // Objective: // ========== // Document disk usage for specific file types. // // Usage: // ====== // Script can be manually executed using the TaskMaster TMRUN command // at the TMConsole (Shell) Screen: // // Example: TMRUN [vol:path\]LOGTYPES.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 LOGTYPES.TSK 01 02:00 // (Executes the 1st of each month at 2:00am) // // TMSCHEDULE ADD LOGTYPES.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 v3.15c (or later), TaskMaster Lite v3.15c (or later) // NetWare v3.12 / v3.2 / v4.1x / v5.x / v6.0 // // 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. // // Comments: // ========= // This task script is provided free of charge and without any warranty or // guarantee of fitness of purpose or performance. // // For additional TaskMaster script examples, visit the Sample Tasks page // on the Avanti Technology, Inc. WEB Site: http://www.avanti-tech.com // //============================================================================= // Check that the version of TaskMaster loaded is compatible (3.24b or later) IF "%TM_VERSION%.%TM_SUBVERSION%%TM_REVISION%"<"3.24b" ECHO. ECHO Error: Incompatible TaskMaster release (requires v3.24b or later)! ECHO. ABORT ENDIF // Define base directory from which to start search (VOL:PATH only). DEFINE %0 SYS: // Make sure base directory exists as defined IF NOT EXIST %0 THEN ABORT // Define base path/file (no .extension) for log and report files // Note: %TASK_PATH% places the log files in the same directory as the task DEFINE %1 %TASK_PATH%\LOGTYPES // Create/open temporary log file to record matching entries OPEN_WRITE %1.TMP TRUNCATE IF ERRORLEVEL ECHO. ECHO Error: Unable to Create/Open Temporary Log file (%1.TMP)! ECHO. ABORT ENDIF // Change the Current Working Directory (CWD) to the base directory CD %0 // Clear record count for temporary processing DEFINE %2 0 // Clear temporary variable used for returned directory name DEFINE %9 // WHILE/LOOP to traverse directory tree during search for specified file types WHILE // Clear temporary variable used for returned file name DEFINE %8 // WHILE/LOOP to search each directory for specified file types WHILE // Define variable %8 as the next matching entry in the file search. // If the first %DIR_FILE_% (%8 is NULL), we must provide a search pattern. IF "%8"=="" DEFINE %8 %DIR_FILE_*.*% ELSE DEFINE %8 %DIR_FILE_% ENDIF // Terminate the WHILE/LOOP is %8 if NULL (i.e., no more files) IF "%8"=="" THEN BREAK // Clear %7 (use as check for matched file) DEFINE %7 // Check returned file for specified name(s) / ext(s) (set %7 accordingly) // Note: Check for any specified name(s) first to avoid ext processing. // File names are returned in DOS (upper case, 8.3) format. // Notice check for both .JPE (Long = .jpeg) and .JPG (Short/DOS), // as well as for .MPE (Long = .mpeg) and .MPG (Short/DOS), IF "%8"=="BADMOVIE.AVI" DEFINE %7 01 ELSEIF SCAN_STRING ".AVI" "%8" DEFINE %7 02 ELSEIF SCAN_STRING ".JPE" "%8" OR SCAN_STRING ".JPG" "%8" DEFINE %7 03 ELSEIF SCAN_STRING ".MOV" "%8" DEFINE %7 04 ELSEIF SCAN_STRING ".MP3" "%8" DEFINE %7 05 ELSEIF SCAN_STRING ".MPE" "%8" OR SCAN_STRING ".MPG" "%8" DEFINE %7 06 ENDIF // IF %7 is NULL, file did not match specified patterns for CONTINUE IF "%7"=="" THEN CONTINUE // Matching entry found so log the information WRITE %7 %CWD%\%8 // Increment record processing count DEFINE %2 %2+=1 LOOP // Define variable %9 as the next matching entry in the directory tree. // If the first %DIR_TREE_% (%9 is NULL), we must provide a base directory. IF "%9"=="" DEFINE %9 %DIR_TREE_%0% ELSE DEFINE %9 %DIR_TREE_% ENDIF // Terminate the WHILE/LOOP is %9 if NULL (i.e., no more directories) IF "%9"=="" THEN BREAK LOOP // Check if any data written to temporary log file IF "%2"=="0" // Record the fact that there was nothing to process WRITE =============================================================== WRITE Total: 0 file(s) / 0 KB (+app.) WRITE. WRITE. // Need to close the temporary file to copy it CLOSE WRITE // Copy the temporary file to the final report file XCOPY %1.TMP %1.LOG IF ERRORLEVEL THEN ABORT ENDIF // Check if any data written to temporary log file IF "%2"=="0" THEN GOTO EOJ // Close the temporary log file used for output CLOSE WRITE // Sort the log file by match pattern ID (i.e., 2 digit code) then file name SORT %1.TMP %1.SRT 1-2, 4-258 IF ERRORLEVEL ECHO. ECHO Error: Unable to SORT Temporary Log file (%1.TMP)! ECHO. ABORT ENDIF // Open the sorted output to read for report generation OPEN_READ %1.SRT IF ERRORLEVEL ECHO. ECHO Error: Unable to Open Sorted Log file (%1.SRT)! ECHO. ABORT ENDIF // Create/open report file to format matching entries OPEN_WRITE %1.LOG TRUNCATE IF ERRORLEVEL ECHO. ECHO Error: Unable to Create/Open Report file (%1.LOG)! ECHO. ABORT ENDIF // Clear count for specific file types (.EXT) DEFINE %4 0 // Clear size (KB) for specific file types (.EXT) DEFINE %5 0 // Clear total count for all file types (.EXT) DEFINE %6 0 // Clear total size (KB) for all file types (.EXT) DEFINE %7 0 // Clear %8 to use for new extension indicator DEFINE %8 // WHILE/LOOP to read/parse/write results WHILE // Read the matching file (full path/file name in original Name Space) READ %3 // Parse the file name into %9 PARSE %9 %3 4-256 PACK // Parse the matching pattern ID (2 digits) into %2 PARSE %2 %3 1-2 // Check if EOF ("%9"=="") // Check if first READ or change of file type (NOT "%2"=="%8") // In either case, file type section header or footer needs to be logged. IF "%9"=="" OR NOT "%2"=="%8" // If %8 is NOT NULL (NOT "%8"=="") then must be a change of file type // so log stats for previous type IF NOT "%8"=="" WRITE --------------------------------------------------------------- WRITE %4 file(s) / %5 KB (+app.) WRITE. WRITE. ENDIF // Check if NULL record (EOF - "%9"=="") and BREAK out of WHILE/LOOP IF "%9"=="" THEN BREAK // Store the new search pattern ID in %8 DEFINE %8 %2 // Write appropriate new file type (.EXT) grouping header IF "%8"=="01" WRITE BADMOVIE.AVI file log: ELSEIF "%8"=="02" WRITE *.AVI file log: ELSEIF "%8"=="03" WRITE *.JPEG file log: ELSEIF "%8"=="04" WRITE *.MOV file log: ELSEIF "%8"=="05" WRITE *.MP3 file log: ELSEIF "%8"=="06" WRITE *.MPEG file log: ENDIF WRITE --------------------------------------------------------------- // Clear count for this file type (.EXT) DEFINE %4 0 // Clear size for this file type (.EXT) DEFINE %5 0 ENDIF // Get the size of the matching file (using 0+= strips any leading zeroes) DEFINE %3 0+=%FILE_SIZE_%9% // Log this matching entry WRITE %9 WRITE Owner: %FILE_OWNER_%9% Created: %FILE_CREATE_%9% Size: %3 // Increment count for this file type (.EXT) DEFINE %4 %4+=1 // Increment count for all file types DEFINE %6 %6+=1 // Convert this file size into KB CALC %3 %3 / 1024 // Increment size (KB) for this file type (.EXT) by this file size CALC %5 %5 + %3 // Increment size (KB) for all file types by this file size CALC %7 %7 + %3 LOOP // Processing complete so summarize the results WRITE =============================================================== WRITE Total: %6 file(s) / %7 KB (+app.) WRITE. WRITE. // Finished so close the READ/WRITE files (proper cleanup) CLOSE READ CLOSE WRITE :EOJ // Cleanup extraneous temporary work files IF EXIST %1.SRT THEN DELETE %1.SRT IF EXIST %1.TMP THEN DELETE %1.TMP