; Note: comment lines in .INI files always start with a semicolon [Template] Description=Use this template to create a job that will monitor a particular file and send an email message with found changes whenever this file changes. [Variables] ; Key values that have their name enclosed in % signs will be used for ; template wizard questionnaire and substitution variables ; such key values should consist of 2 comma separated parts: ; 1. Field Edit Style (EDIT, YES/NO, FILE BROWSE, ; DIR BROWSE, PROCESS BROWSE, ; FTP BROWSE, MAIL PROFILE LIST, ; REMOTE FILE BROWSE, REMOTE DIR BROWSE, ; REMOTE AGENT LIST, DB PROFILE LIST) ; 2. Prompt ; ; Example: %VAR%=EDIT,What is the name of the service that you want to monitor? ; ; Key values that don't have their name enclosed in % signs will be used for ; job properties (See online help on "Job property names for use with JDL command" ; topic for more details). ; ; Example: DAY_NUMBER=1 %FILE%=FILE BROWSE,Which file do you want to monitor? Enter full file name including path. %EMAIL_RECIPIENT%=EDIT,To whom do you want to sent the email alert when this file changes: %EMAIL_PROFILE%=MAIL PROFILE LIST,If you use MAPI email interface, then which email profile do you want to use? If you use Lotus Notes or SMTP email interfaces, enter User ID required for logging to your email system. %EMAIL_PASSWORD%=EDIT,If you are required to login to your email system, what is your password: JOB_TYPE=S SCHEDULE_TYPE=B ASYNC=Y SKIP=N DESCRIPTION=This job monitors file. If it detects that the file has changed, it finds latest changes and then it sends an email alert to the specified recipient. ; Notes: The script bellow can include substitution variables. ; Substitution variables must be specified in %VAR% format ; where VAR is the variable name. ; ; Everything after the next line will be used for the template script. ;======================================================================================== [Body] // This script is implemented as endless loop to ensure // continues file change monitoring Dim changed, boolean Dim file_date, date Dim file_time, time Dim datetime1, datetime Dim datetime2, datetime Dim message, string Dim has_snapshot, boolean Dim watch_file, string, "%FILE%" Dim snapshot_file, string, "%FILE%_snapshot" Dim new1, number Dim new2, number Dim new_text, string Dim deleted_text, string Dim file_number, number Dim no_diff, boolean Dim end_of_file, boolean Dim line, string Dim tag, string // Get file modification date and time FileDate watch_file, file_date FileTime watch_file, file_time DateTime file_date, file_time, datetime1 // Check if have a snapshot of that file, if not create it FileExists snapshot_file, has_snapshot IfThen has_snapshot, CHECK_TIME // No snapshot exist yet, this is the very first run // Create snapshot (e.g most recent copy) FileCopy watch_file, snapshot_file CHECK_TIME: // Wait 30 seconds and check file modification date and time Wait 30 FileDate watch_file, file_date FileTime watch_file, file_time DateTime file_date, file_time, datetime2 // Compare file modification date and time NotEqual datetime1, datetime2, changed // If datetime has changed, find changes and send email message, otherwise keep checking If changed, FIND_CHANGES, CHECK_TIME FIND_CHANGES: FileCompare watch_file, snapshot_file, "c:\\temp\\$$$diff.tmp", new1, new2 Set new_text, "" Set deleted_text, "" NotfileExists "c:\\temp\\$$$diff.tmp", no_diff IfThen no_diff, EMAIL // Read "difference" file line by line and find differences FileOpen "c:\\temp\\$$$diff.tmp", "LineMode", "Read", False, file_number EOF file_number, end_of_file LoopUntil end_of_file, END_LOOP // Read next line FileRead file_number, line // Get tag and analyze it Left line, 3, tag Mid line, 4, 10000, line ChooseCase tag, END_CHOOSE Case " !" // deleted text found ConcatEx deleted_text, line, "\\r\\n", deleted_text END_CHOOSE: // Check if we reached end of file EOF file_number, end_of_file END_LOOP: EMAIL: // send email alert ConcatEx "File \"%FILE%\" was changed on ", datetime2, "\\r\\n", & "The following new lines were added: \\r\\n", new_text, & "The following lines were deleted: \\r\\n", deleted_text, & message MailSend "%EMAIL_PROFILE%", "%EMAIL_PASSWORD%", "%EMAIL_RECIPIENT%", & "File change detected", message // Update snapshot FileCopy watch_file, snapshot_file // Reset date criteria Set datetime1, datetime2 GoTo CHECK_TIME