Link to home
Start Free TrialLog in
Avatar of iNc0g
iNc0gFlag for Israel

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.
ASKER CERTIFIED SOLUTION
Avatar of rscottvan
rscottvan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iNc0g

ASKER

I ran the script in order to test it, therefor I changed:

If DateDiff("H",oFile.DateLastModified,Now) > 48 then

To:

If DateDiff("M",oFile.DateLastModified,Now) > 2 then

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!
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iNc0g

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 ?
This could be made a little more elegant, but should do the trick.  

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

Open in new window

Hi, this should work a little cleaner.

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

Open in new window