Create Notification Script

Top  Previous  Next

We will use EventSentry's ability to trigger any process from an event to trigger our VBScript below to emails us the latest log file.

 

Blat

Blat.exe is a public domain, freeware command-line email utility, similar to sendmail on Linux/Unix (though it is only an email client, it is not a MTA etc.). Download blat from http://www.blat.net, and we recommend that you save the blat.exe file in the same directory where you are going to put the .vbs script later on, for example C:\Batch\blat.exe.

 

Visual Basic Script File

Using any text editor, create a new file and immediately save it in a folder on your server, for example:

 

       c:\batch\es_email_ntbackup_log.vbs

 

Again, we recommend that you save this file in the same folder where you saved blat.exe. Then, paste the formatted output below into the file and modify all the values shown in bold. This is imperative, since you need to specify your email configuration. All required values are explained below:

 

SmtpServer

The host name or IP address of your SMTP server

EmailSender

The email address that will appear as the sender

EmailRecipient

The email address of the recipient

LogFolder

All log files from NTBackup are written to this directory, but you might have to replace Administrator with the actual username under which your NTBackup is being scheduled.

Compress

Set this value to one if you want to compress the log file (highly recommended) and if you have a zip application installed that supports command-line based compression

CompressExe

The path to the command-line .exe compression utility. If you do not use Winzip then you will have to also change the command-line argument below.

EmailClient

Full path to the blat.exe file

 

' Author: NETIKUS.NET ltd

' Date:   9/27/2006

' Title:  Email NTBackup Log file using blat.exe

' Description: Emails the latest ntbackup.exe log file using blat.exe, and optionally compresses the attachment

 

Dim SmtpServer

Dim EmailSender, EmailRecipient, EmailSubject

 

Dim aFile

Dim fNewest, fNewestZipped

Dim oFolder

Dim LogFolder

Dim numFiles

 

Dim Compress, CompressExe

Dim EmailClient

 

' Set your preferences here *

SmtpServer                = "emailserver-hostname"

EmailSender                = "SERVER@yourdomain.com"

EmailRecipient        = "youremail@yourdomain.com"

EmailSubject        = "NTBackup Log File"

LogFolder                = "C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data"

Compress                = 0        ' Set to 1 if you have Winzip installed

CompressExe                = "C:\Program Files\Winzip\wzzip"

EmailClient                = "C:\Batch\blat.exe"

 

Set WshShell        = WScript.CreateObject("WScript.Shell")

Set oFolder                = CreateObject("Scripting.FileSystemObject").GetFolder(LogFolder)

 

numFiles = 0

 

' Find log file with latest time stamp

For Each aFile In oFolder.Files

       If Right(aFile.Name, 4) = ".log" Then

               numFiles = numFiles + 1

         

               If fNewest = "" or fNewest = null Then

                       Set fNewest = aFile

               Else

                       If fNewest.DateLastModified < aFile.DateLastModified Then

                               Set fNewest = aFile

                       End If

               End If

       End If

Next

 

' Only compress if configured to do so

If Compress = 1 Then

       fNewestZipped = fNewest & ".zip"

Else

       fNewestZipped = fNewest

End If

 

' Email log file

If numFiles > 0 Then

       If Compress = 1 Then

               CommandLine = """" & CompressExe & """ -u """ & fNewestZipped & """ """ & LogFolder & "\" & fNewest.Name & """"

               WshShell.Run CommandLine, 3, 1

       End If

       

       WshShell.Run EmailClient & " - -body ""NTBackup Log File"" -attach """ & fNewestZipped & """ -server " & SmtpServer & " -f " & EmailSender & " -subject " & chr(34) & EmailSubject & chr(34) & " -to " & EmailRecipient, 3, 1

End If