Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'***************************************************
'Search for failed backup in log file
'By Mark D. MacLachlan
'Creation date: 02/17/2003
'Modifications: 06/04/2003 Added support to look for job not run due to no media
' 03/17/2004 Moved variables needing change to top of script for easy editing
' 4/28/2005 Removed RegExpressions testing. Testing now uses Instr to get status.
' Modified date detection as datediff was returning negative numbers.
'***************************************************
On Error Resume Next
'Declare our variables
Dim Status, oFSO, objShell, logFile , myToday, date_modified, daysbetween
Dim oName, ODomain, oMyIP, oTo
Const ForReading = 1
' Set the company specific information
'Log file location
folder_path = "C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data"
' Company Internet Domain Name
ODomain = "company.com"
' Set the SMTP server IP
oMyIP = "192.168.1.92"
' Where do you want the message to be delivered
oTo = "support@company.com"
myToday = FormatDateTime(Now(), vbShortDate)
'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("wscript.shell")
'open the data file
set fld = oFSO.getfolder(folder_path)
set fldContents=fld.files
For each f in fldContents
If right(f.name,3)="log" Then
date_modified=FormatDateTime(f.DateLastModified, vbShortDate)
daysbetween= DateDiff("d",myToday,date_modified)
If daysbetween <0 And daysbetween >(-2) then
get_backup_log_file = f.name
Else
get_backup_log_file = "No file"
End if
End if
Next
logFile = get_backup_log_file
'MsgBox logFile
'wscript.quit
'if no data file then backup did not run
If logFile="No file" Then
Status ="backup did not run"
oTextStream ="No backup file to include"
SendMail Status,oTextStream
Else
oTextStream = oFSO.OpenTextFile(folder_path & "\" & logFile, ForReading, False, -1).ReadAll
'MsgBox "Contents of array will be" & vbCrLf & oTextStream
myArray=Split(oTextStream,vbCrLf, -1, 1)
Status = "Backup Believed To Have Succeeded"
'Check if backup ran but failed
For Each entry In myArray
'msgBox entry
If Instr(1,entry,"did not successfully complete") Then
Status = "Backup Failed"
ElseIf Instr(1,entry,"operation was not performed") Then
Status = "Backup Did Not Run"
End If
Next
'msgBox Status
End If
SendMail Status,oTextStream
Function SendMail(backupText,oTextStream)
'now send the message about the status
' Get the computer name
Set WshNetwork = CreateObject("WScript.Network")
oName = WshNetwork.ComputerName
' Set the visual basic constants as they do not exist within VBScript.
' Do not set your smtp server information here.
Const cdoSendUsingMethod = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing",[/URL] _
cdoSendUsingPort = 2, _
cdoSMTPServer = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver"[/URL]
'Create the CDO connections.
Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
'SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
'Set the SMTP server address here.
.Item(cdoSMTPServer) = oMyIP
.Update
End With
'Set the message properties.
With iMsg
Set .Configuration = iConf
.To = oTo
.From = oName & "@" & oDomain
.Subject = oName & " "& Status
.TextBody = "Server " & oName & " at company " & ODomain & " " & Status & " " & Now & vbCrLf & oTextStream
End With
Wscript.Echo iMsg.TextBody
'An attachment can be included.
'iMsg.AddAttachment logfile
'Send the message.
iMsg.Send
WScript.Quit
End Function