Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

windows script to compare file date n system date 1

Status
Not open for further replies.

sugu

Programmer
Jan 12, 2004
90
SG
Hi,

I'm new to windows scripting. I my server(win server 2003) to send email to me on my colleagues when a backup (using windows backup utility)has been done on the server. I'm goin to use blat to send the email. but since the back utility creates the log file name differently for each backup process (eg backup1.log, backup2.log, etc.) i need to add a script to send only the file created on that date(following the system date).
I do i do that. I need it urgently.
Thanks in advance

-su
 
Oh, who do you love?

[script]
'==========================================================================
'
' NAME: emailNTBackupLogs.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: ' DATE : 02/17/2003
'
' COMMENT: <comment>
'
'==========================================================================

On Error Resume Next

'Declare our variables
Dim objRegExpr , objMatch, oFSO, objShell, logFile , myDay, myMonth, daytoday
Dim oName, ODomain, oMyIP, oTo
Const ForReading = 1


'Create an instance of the regexp object
Set objRegExpr = New regexp
objRegExpr.Pattern = "did not successfully complete"
objRegExpr.Global = True
objRegExpr.IgnoreCase = True

todayCheck= left(Now,10)

if mid(todayCheck,3,1) = "/" then
myMonth="2"
else
myMonth="1"
end if

if (myMonth = "2") and (mid(todayCheck,6,1) = "/") then
myDay="2"
elseif (myMonth = "2") and (mid(todayCheck,5,1) = "/") then
myDay="1"
elseif (myMonth="1") and (mid(todayCheck,4,1) = "/") then
myDay="1"
else
myDay="2"
end if



'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("wscript.shell")

'open the data file

folder_path = "C:\WINNT\Profiles\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data"

set fld = oFSO.getfolder(folder_path)
set fldContents=fld.files

if (myMonth = 2) and (myDay = 2) then
daytoday = mid(todayCheck,4,2)
todayCheckMonth = left(todayCheck,2)
elseif (myMonth = 2) and (myDay = 1) then
daytoday = mid(todayCheck,4,1)
todayCheck= left(Now,9)
todayCheckMonth = left(todayCheck,2)
elseif (myMonth = 1) and (myDay = 2) then
daytoday = mid(todayCheck,3,2)
todayCheck= left(Now,9)
todayCheckMonth = left(todayCheck,1)
elseif (myMonth = 1) and (myDay = 1) then
daytoday = mid(todayCheck,3,1)
todayCheck= left(Now,8)
todayCheckMonth = left(todayCheck,1)
end if

todayCheckYear = right(todayCheck,4)



for each f in fldContents

fdateCheck= left(f.DateLastModified,10)

if (mid(fdateCheck,3,1) = "/") and (mid(fdateCheck,6,1) = "/") then
date_modified= left(f.DateLastModified,10)
date_mod_day = mid(date_modified,4,2)
date_mod_month = left(date_modified,2)
date_mod_year = right(date_modified,4)
elseif (mid(fdateCheck,3,1) = "/") and (mid(fdateCheck,5,1) = "/") then
date_modified= left(f.DateLastModified,9)
date_mod_day = mid(date_modified,4,1)
date_mod_month = left(date_modified,2)
date_mod_year = right(date_modified,4)
elseif (mid(fdateCheck,2,1) = "/") and (mid(fdateCheck,5,1) = "/") then
date_modified= left(f.DateLastModified,9)
date_mod_day = mid(date_modified,3,2)
date_mod_month = left(date_modified,1)
date_mod_year = right(date_modified,4)
elseif (mid(fdateCheck,2,1) = "/") and (mid(fdateCheck,4,1) = "/") then
date_modified= left(f.DateLastModified,8)
date_mod_day = mid(date_modified,3,1)
date_mod_month = left(date_modified,1)
date_mod_year = right(date_modified,4)
end if



if (date_mod_year = todayCheckYear) and (date_mod_month = todayCheckMonth) then

num_days = daytoday - date_mod_day
Else
num_days = "999"
end if


if (num_days < 2) then'and (left(f.name,3)="log") then
get_backup_log_file = f.name
end if

'if get_backup_log_file ="" then
' get_backup_log_file = "No file"
'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
backupText="backup did not run"
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)

For Each entry In myArray
'Declare a variable to hold our collection of Matches
'Now, Execute the regular expression search
Set colMatches = objRegExpr.Execute(entry)

If colMatches.Count = 0 Then
backupState = 0 'backup failed
Else
backupState = 1 'backup succeeded
End If
Next

Select Case backupState
Case 0
backupText="backup believed to have succeeded, verification needed. "
Case 1
backupText="backup failed"
End Select
End If

'now send the message about the status
' Get the computer name
Set WshNetwork = CreateObject("WScript.Network")
oName = WshNetwork.ComputerName

' Set the company specific information

' Company Internet Domain Name
ODomain = "miragehomes.com"
' Set the SMTP server IP
oMyIP = "10.0.0.2"
' Where do you want the message to be delivered
oTo = "support@itsynergy.com"



' Set the visual basic constants as they do not exist within VBScript.
' Do not set your smtp server information here.
Const cdoSendUsingMethod = " _
cdoSendUsingPort = 2, _
cdoSMTPServer = "
'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 & " "& backupText
.TextBody = "Server " & oName & " at company " & ODomain & " " & backupText & " " & Now & vbCrLf & oTextStream


End With

'An attachment can be included.
'iMsg.AddAttachment logfile

'Send the message.
iMsg.Send
WScript.Quit


[/script]

I hope you find this post helpful.

Regards,

Mark
 

thanks Mark! got it working ;)


su
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top