iNc0g
asked on
Script to notify administrator if file older than 48 hours
Hi,
OS: Server 2003 SP2
I need a script/schedule task to notify me somehow (email/alert) when file c:\xxx.dat is older than 48 hours , is there a way to accomplish this ?
Thanks.
OS: Server 2003 SP2
I need a script/schedule task to notify me somehow (email/alert) when file c:\xxx.dat is older than 48 hours , is there a way to accomplish this ?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks, you guys are great.
1 last thing, how do I add an action to email if the file does not exist at all ?
1 last thing, how do I add an action to email if the file does not exist at all ?
This could be made a little more elegant, but should do the trick.
And... remove all the brackets. < >
And... remove all the brackets. < >
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists("c:\xxx.dat") then
Dim oFile : Set oFile = oFSO.GetFile("c:\xxx.dat")
If DateDiff("H",oFile.DateLastModified,Now) > 48 then
Dim oEMail
Set oEMail = CreateObject("CDO.Message")
oEMail.From = "myscript@mydomain.com"
oEMail.To = "myemail@mydomain.com"
oEMail.Subject = "File c:\xxx.dat age exceeds 48 hours"
oEMail.Textbody = "enter body here"
oEMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oEMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "enter mail server IP Address here"
oEMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oEMail.Configuration.Fields.Update
oEMail.Send
End If
Else
Dim oEMail
Set oEMail = CreateObject("CDO.Message")
oEMail.From = "myscript@mydomain.com"
oEMail.To = "myemail@mydomain.com"
oEMail.Subject = "File c:\xxx.dat does not exist"
oEMail.Textbody = "enter body here"
oEMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oEMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "enter mail server IP Address here"
oEMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oEMail.Configuration.Fields.Update
oEMail.Send
End If
Hi, this should work a little cleaner.
Regards,
Rob.
Regards,
Rob.
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
strFile = "C:\xxx.dat"
Set oEMail = CreateObject("CDO.Message")
oEMail.From = "myscript@mydomain.com"
oEMail.To = "myemail@mydomain.com"
If oFSO.FileExists(strFile) then
Dim oFile : Set oFile = oFSO.GetFile(strFile)
If DateDiff("H",oFile.DateLastModified,Now) > 48 then
oEMail.Subject = "File " & strFile & " age exceeds 48 hours"
oEMail.Textbody = "enter body here"
End If
Else
oEMail.Subject = "File " & strFile & " does not exist"
oEMail.Textbody = "enter body here"
End If
oEMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oEMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "enter mail server IP Address here"
oEMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oEMail.Configuration.Fields.Update
oEMail.Send
ASKER
If DateDiff("H",oFile.DateLas
To:
If DateDiff("M",oFile.DateLas
So it's supposed to identify 2 minutes difference and email me, but it didn't ..
In those lines I kept the < > signs:
oEMail.Textbody = "<Please check file>"
"<191.191.191.191>"
What could be the problem ?
doesn't the script require user and pwd in order to run .. ?
Thanks!