//============================================================================= // // Task: CHK_VOLS.TSK // Checks volumes for low space threshold and sends eMail alerts // Author: Avanti Technology, Inc. // http://www.avanti-tech.com // Version: 1.00 - Initial Release (28 Apr 2009) // // Description: // ============ // Checks all mounted volumes for a minimum amount of Free Space and // sends an eMail message if the minimum threshold is crossed. // // Objective: // ========== // Can be scheduled to provide periodic monitoring and alerts on low disk space. // // Usage: // ====== // Script can be manually executed using the TaskMaster TMRUN command // at the TMConsole (Shell) Screen: // // Example: TMRUN [vol:path\]CHK_VOLS.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 CHK_VOLS.TSK 01 02:00 // (Executes the 1st of each month at 2:00am) // // TMSCHEDULE ADD CHK_VOLS.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. // // Note: Logic has been incorporated to avoid multiple concurrent executions. // Therefore, it can be scheduled as frequently as desired to insure // continuous operation. // // Compatibility: // ============== // This task has been tested on the following platforms without demonstrating // any compatibility issues or any other reported/confirmed conflicts: // TaskMaster v4.20 (or later), TaskMaster Lite v4.20 (or later) // NetWare v5.x / v6.x / OESx (NetWare kernel) // (Note: eMail alerts not supported in TaskMaster Lite [TMLite]) // // 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 // // Note: Search for {MODIFY} comments indicating items which need // to be modified or renamed (as appropriate). // //============================================================================= // Check that the version of TaskMaster loaded is compatible (4.20 or later) IF "%TM_VERSION%.%TM_SUBVERSION%"<"4.20" // Echo the problem message to the screen ECHO. ECHO Error: Incompatible TaskMaster release (requires v4.20 or later)! ECHO. ABORT ENDIF // Check if already active. Terminate this copy if already active. IF ACTIVE_TASK %TASK% ECHO. ECHO %TASK%: Already active! Terminating... ECHO. EXIT ENDIF // Use VOLINFO, redirecting output to a temporary file, to find mounted volumes VOLINFO >%TASK_PATH%\%TASK_FILE%.tmp // Read the redirected output from VOLINFO (check for errors) OPEN READ %TASK_PATH%\%TASK_FILE%.tmp // Check for OPEN READ errors when attempting to access the temporary file // with the redirected VOLINFO data IF ERRORLEVEL // Create error log file and record the problem OPEN WRITE %TASK_PATH%\%TASK_FILE%.err WRITE [%YEAR%/%MONTH%/%DAY%/%YEAR% %HOUR24%:%MINUTE%:%SECOND%] WRITE ??? OPEN READ %TASK_PATH%\%TASK_FILE%.tmp failed - Unable to process ??? WRITE CLOSE ABORT ENDIF // Alias default variable names to more meaningful variable names VARALIAS %VAR10% %LEN% VARALIAS %VAR11% %VOLUME% VARALIAS %VAR12% %MIN_VOL_FREE% VARALIAS %VAR13% %SMTP_TO% VARALIAS %VAR14% %SMTP_FROM% VARALIAS %VAR15% %SMTP_SERVER% VARALIAS %VAR16% %SMTP_MSG% // {MODIFY} Define minimum free space threshold (fixed length numeric - digits) DEFINE %MIN_VOL_FREE% 010 // {MODIFY} Define the eMail address to whom alerts should be sent DEFINE %SMTP_TO% user@domain.com // {MODIFY} Define the eMail address from whom alerts should be sent DEFINE %SMTP_FROM% taskmaster@domain.com // {MODIFY} Define name (smtp.domain.com) or ip (127.0.0.1) of SMTP Server DEFINE %SMTP_SERVER% 127.0.0.1 // WHILE/LOOP to parse mounted volumes from VOLINFO redirected output // The mounted volume names are then used to check free space status WHILE // Read first/next record from VOLINFO redirected output log file READ %VOLUME% 1-17 // ERRORLEVEL set on Enf Of File (EOF) IF ERRORLEVEL THEN BREAK // Check for valid Volume name IF NOT SCAN_STRING ":" "%VOLUME%" THEN CONTINUE // REFORMAT the read data to strip trailing spaces from Volume name REFORMAT %VOLUME% PACK // Skip the _ADMIN: volume since it is dynamic IF "%VOLUME%"=="_ADMIN:" THEN CONTINUE // Set the Current Working Directory (CWD) to the root of the Volume CD %VOLUME% // Check for success IF ERRORLEVEL // Create/open error log file and record the problem OPEN WRITE %TASK_PATH%\%TASK_FILE%.err WRITE [%YEAR%/%MONTH%/%DAY%/%YEAR% %HOUR24%:%MINUTE%:%SECOND%] WRITE ??? CD %VOLUME% failed - Unable to check %VOLUME% status ??? WRITE CLOSE // Resume processing with next record in VOLINFO redirected output log file CONTINUE ENDIF IF "%VOL_FREE%"<"%MIN_VOL_FREE%" // Define the proposed eMail file name DEFINE %SMTP_MSG% %TASK_PATH%\%TASK_FILE%.%VOLUME% // Determine the length of the proposed eMail file name FINDLEN %LEN% %SMTP_MSG% // Decrement the length by 1 (removes the : from the Volume name) // Note: Can use either of the following... // CALC %LEN% %LEN% - 1 // DEFINE %LEN% %LEN%-=1 DEFINE %LEN% %LEN%-=1 // Truncate the eMail file name to exclude the trailing : in the Volume name REFORMAT %SMTP_MSG% %LEN% // Create/open (truncate) temporary file to compose eMail message OPEN WRITE %SMTP_MSG% TRUNCATE // Resume processing with next record in VOLINFO redirected output log file // if unable to compose eMail message for this Volume IF ERRORLEVEL THEN CONTINUE // Compose basic eMail message (header and body) WRITE To: %SMTP_TO% WRITE From: %SMTP_FROM% WRITE Subject: %TASK_FILE% - %SERVER%/%VOLUME% is low on space WRITE WRITE %SERVER%/%VOLUME% WRITE Free Space: %VOL_FREE% (includes Limbo/Purgeable Space) WRITE Purgeable: %VOL_PURGEABLE% WRITE // Close (only) the eMail message file CLOSE WRITE // Send the eMail message via the SMTP Server TMSMTP %SMTP_SERVER% %SMTP_MSG% ENDIF LOOP // Close all open files (proper cleanup) CLOSE