Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Append Date to NTBackup Log File

Reply
 
Old 06-27-2009   #1 (permalink)
Manlytrash


 
 

Append Date to NTBackup Log File

All,

I have a script that currently send me an email of the NTBackup log
and tells me if there are any warnings or errors in it and places that
in the subject and body of the email. What I want it to do also is
create a new log file from the current log file that it read and save
it to disk. New log file name would be dated and have computer name.
I've looked around and can't seem to find anything that works. Thanks
for your help!


**************************************Start of
Script*************************************************

'
************************************************************************************
' * Send NT Backup Log by Email Script
' * Comments:
' * Created from lots of code snippets on the internet!
' * Will send by email the last modified log file.
' * Feel free to use/modify for your own needs.
' * No guarantees though although it works for me :-)
'
************************************************************************************

Option Explicit

' Defined Variables
Dim filesys, filetxt, fso, f, file, strtext, filetext, result_value,
SMTP_AUTH
Dim iMsg, Flds, iConf, CorpoMessaggioConst, att_value, mex,
oWshNetwork, strComputerName

' Set constants
Const cdoAnonymous = 0 'No User/Password is needed, open relay
Const cdoBasic = 1 'Basic password sent in clear text, this
is the most common!
Const cdoNTLM = 2 'Password retreived by logged on user(For
CDOEX, not implimented yet)

'Set Variables, these are the only parts that need changed to suit
your needs!
Const BACKUP_LOG_PATH = "C:\Documents and Settings\administrator\Local
Settings\Application Data\Microsoft\Windows NT\NTBackup\data"
Const DEFAULT_SENDER = "sender@xxxxxx" 'From email
address
Const DEFAULT_USER = "user"
'User Account
Const DEFAULT_PASS = "password" 'User
Password
Const DEFAULT_RECIP = "recip@xxxxxx" 'To email
address
Const DEFAULT_RECIPCC = "recipcc@xxxxxx" 'CC email
address
Const DEFAULT_SUBJECT = "NT Backup Log For Client" 'Default email
subject
Const DEFAULT_CLIENT = "Company Name" 'Client's
Company Name
Const SMTP_SERVER = "mail.domain.com" 'Email
Server
Const SMTP_PORT =
25 'SMTP Port
SMTP_AUTH = 1 ' Choose
one of the above; Anonymous, Basic or NTLM
Const SMTP_TIMEOUT = 60 ' Seconds to
wait for SMTP Server

' Set variable defaults
Set oWshNetwork = WScript.CreateObject("WScript.Network")
strComputerName = oWshNetwork.ComputerName

' Start script
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(BACKUP_LOG_PATH)
att_value = ""
For Each file In f.Files
if DateDiff("d",file.DateLastModified,now) = 0 and ucase(right
(file.name, 3)) = "LOG" then
att_value = file.path
end if
Next
if att_value = "" then
mex = "FAILED"
result_value = "NT Backup Log Not Found"
else

'Open Log file and read for errors
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile(att_value, ForReading,, True)
strText = fileTxt.ReadAll
filetxt.close
if instr(ucase(strText), "ERROR") <> 0 or instr(ucase(strText),
"UNABLE") <> 0 then
mex = "FAILED!"
result_value = "NT Backup Log Check found Errors!"
else
mex = "SUCCESFULL"
result_value = "NT Backup Log Check seems OK"
end if
End if

' Start sending email
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Flds("http://schemas.microsoft.com/cdo/configuration/
sendusing") = 2' SMTP By Port
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
SMTP_SERVER
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= SMTP_PORT
Flds("http://schemas.microsoft.com/cdo/configuration/
smtpauthenticate") = SMTP_AUTH
Flds("http://schemas.microsoft.com/cdo/configuration/
smtpconnectiontimeout") = SMTP_TIMEOUT
Flds("http://schemas.microsoft.com/cdo/configuration/sendusername") =
DEFAULT_USER
Flds("http://schemas.microsoft.com/cdo/configuration/sendpassword") =
DEFAULT_PASS
Flds.Update
With iMsg
Set .Configuration = iConf
.To = DEFAULT_RECIP
.Cc = DEFAULT_RECIPCC
.From = DEFAULT_SENDER
.Subject = DEFAULT_SUBJECT & " - " & DEFAULT_CLIENT & " - " &
strComputerName & " - " & Mex
.TextBody = result_value
if att_value <> "" then
.AddAttachment att_value
end if
.Send
End With

*************************End of
Script**********************************


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Need help with log ( text ) file - write vs append VB Script
VB Script that searches a file for different text, with an append. VB Script
Can't append date to file name through a ForEach Loop? PowerShell
Having all Export files append to 1 file, xls, or csv... PowerShell
Photo date taken vs. file date Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46