Okay,
First of all I am very very new to scripting…I am running ntbackup via a scheduled task and have a vbscript running (that I found on the web) that sends me an email with the log file attached after every backup. I was hoping to have the text in the log file sent in the body of the email so I don’t have to open it everyday. (I have been looking around and can’t find the proper syntax). Here is the script I am using:
‘ Dim variables
Dim oFSO, oWshNetwork, oCDO, oFolder, oFiles, oFile
dim strFileName, strComputerName
‘ Create Objects
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
Set oWshNetwork = WScript.CreateObject(“WScript.Network”)
‘ Set constants
Const BACKUP_LOG_PATH = “C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data”
Const EMAIL_RECIPIENT = “my email@.com”
‘ Set variable defaults
strFileName = “”
strComputerName = oWshNetwork.ComputerName
‘ Start script
Set oFolder = oFSO.GetFolder(BACKUP_LOG_PATH)
Set oFiles = oFolder.Files
For Each oFile in oFiles
If oFSO.GetExtensionName(oFile.Name) = “log” Then
If DateValue(oFile.DateLastModified) = Date() Then
strFileName = oFile.Name
Exit For
End If
End If
Next
If strFileName <> “” Then
EmailLog(strFileName)
Else
EmailError
End If
Sub EmailLog(logFilePath)
Set oCDO = CreateObject(“CDO.Message”)
oCDO.Subject = “Backup Log – ” & strComputerName
oCDO.From = strComputerName & “@domain.com”
oCDO.To = EMAIL_RECIPIENT
oCDO.TextBody = “Backup log attached for ” & strComputerName
oCDO.AddAttachment BACKUP_LOG_PATH & “\” & logFilePath
oCDO.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
oCDO.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) =”my mail server”
oCDO.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
oCDO.Configuration.Fields.Update
oCDO.Send
set oCDO = Nothing
End Sub
Sub EmailError
Set oCDO = CreateObject(“CDO.Message”)
oCDO.Subject = “Backup Log Missing – ” & strComputerName
oCDO.From = strComputerName & “@domain.com”
oCDO.To = EMAIL_RECIPIENT
oCDO.TextBody = “No backup log found on ” & strComputerName & ” for today”
oCDO.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
oCDO.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) =”my mailserver”
oCDO.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
oCDO.Configuration.Fields.Update
oCDO.Send
set oCDO = Nothing
End Sub
set oFSO = Nothing
Set oWshNetwork = Nothing