//////////////////////////////////////////////////////////////////////////////// // // Task: SYNCMAIL.TSK // (Sample SYNC task which E-Mails the results via SMTP) // Author: Avanti Technology, Inc. // http://www.avanti-tech.com // Version: 1.0 - Initial Release // 1.1 - Improved error handling // 1.2 - Added logging of errors to E-Mailed summary // 1.3 - Added support for multiple SYNC reports in one SMTP message // // Description: // ============ // Basic SYNC with only errors logged and the final log file E-Mailed via SMTP. // // Objective: // ========== // Automate notification of a completed SYNC. // // Usage: // ====== // Script can be manually executed using the TaskMaster TMRUN command // at the TMConsole (Shell) Screen: // // Example: TMRUN [vol:path\]SYNCMAIL.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 SYNCMAIL.TSK 01 02:00 // (Executes the 1st of each month at 2:00am) // // TMSCHEDULE ADD SYNCMAIL.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.02 (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.02" // Report the status ECHO. ECHO Error: Incompatible TaskMaster release (requires v4.02 or later)! ECHO. ABORT ENDIF // First, define some custom variables to make the script easier to read and // manage using the 100 Dynamic (User Defined) Variables in TaskMaster. // // The Dynamic (User Defined) Variables %0 - %9 initially contain any command // line passed parameters (arguments) for manually executed tasks (TMRUN) and // can be used with a script. // The Dynamic (User Defined) Variables %VAR00% - %VAR99% are also available. // // Important Note: %0 - %9 and %VAR00% - %VAR09% are the same // (i.e., two different names for the same set of variables). // // To make it even easier to read and manage, use the VARALIAS Batch // Command (introduced in TaskMaster v4) to define alias names for the // Dynamic (User Defined) Variables to be used. // When using VARALIAS, the new variable name must begin and end with a %, // cannot contain any spaces, cannot conflict with any existing System // Environment Variable definition, and cannot exceed 15 bytes (including %). // // Note: These VARALIAS definitions are temporary for this task only // and do not pass to other CALL or TMRUN executed tasks. VARALIAS %VAR11% %SYNC_DST% VARALIAS %VAR12% %SYNC_LOG% VARALIAS %VAR13% %SYNC_SRC% VARALIAS %VAR14% %SMTP_TO% VARALIAS %VAR15% %SMTP_FROM% VARALIAS %VAR16% %SMTP_SRVR% // Define the SYNC source Volume:Path DEFINE %SYNC_SRC% VOL:PATH\*.* // Define the SYNC destination Server/Volume:Path DEFINE %SYNC_DST% SERVER/VOL:PATH // Define the SYNC output log file (uses the current task vol:path/name.LOG) DEFINE %SYNC_LOG% %TASK_PATH%\%TASK_FILE%.LOG // Define the recipient of the STMP E-Mail message DEFINE %SMTP_TO% name@domain.cci // Define the sender to send the STMP E-Mail message DEFINE %SMTP_FROM% name@domain.cci // Define the STMP Server address (must be a full URL or dot.notated address) DEFINE %SMTP_SRVR% smtp.domain.com // Open the SYNC log file so that the E-Mail header info can be written OPEN WRITE #0 %SYNC_LOG% TRUNCATE // Check for ERRORLEVEL and process accordingly IF ERRORLEVEL // Report the status ECHO. ECHO Error: Unable to create/truncate log file (%SYNC_LOG%)! ECHO. ABORT ENDIF // Write the basic E-Mail message header // Notes: To: & From: required, Subject: optional (Date: auto generated) WRITE #0 To: %SMTP_TO% WRITE #0 From: %SMTP_FROM% WRITE #0 Subject: SYNC Job Summary WRITE #0 // Close the log file so SYNC can redirect output to it CLOSE WRITE #0 // Perform the actual SYNC (full mirrored SYNC) // Note: The /W option specifies to only log errors, not all activity. SYNC %SYNC_SRC% %SYNC_DST% /a /d /h /i /l /s /v /w /# >>%SYNC_LOG% // Note: If you want to include additional SYNC commands within the same // task / E-Mail, insert them above (just below the first SYNC), // replace the %SYNC_SRC% and %SYNC_DST% defined variables with // fully specified source and destination parameters. // Send the E-Mail (be sure to read the TMSMTP section in the User's Guide) IF EXIST %SYNC_LOG% THEN TMSMTP %SMTP_SRVR% %SYNC_LOG%