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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text file size monitor

Status
Not open for further replies.

k3lvin

Technical User
Jan 13, 2008
143
GB
Hey there,

We have a text file that gets constantly filled with data. Sometimes this file stops filling up for unkonwn reasons. Is there some monitoring software that can email alerts when a file size does not change for a desired amount of time? Would be perfect for an issue we having.

Thanks
 
I put together a quick, though not heavily tested script, that could do it for you. You'll need to make some changes for your environment. It's also only configured to check a local file. I'm sure there are improvements to me made as well.

All you need to do is copy and save this as a .vbs file and then create a scheduled task to run (and repeat every x mins/hours) this script. I recommend testing first, as always.

'Code starts below.

Dim WshShell, objfso, objFile1, objFileMonitorData, objEmail
Dim lngSize1, lngSize2, strCurrDir, strFileToMonitor, strFileMonitorText

'on error resume next
Set WshShell = CreateObject("Wscript.Shell")
set objfso = CreateObject("Scripting.FileSystemObject")

strFileToMonitor = "path\to\file"
strCurrDir = WshShell.CurrentDirectory

If Not objfso.FileExists(strFileToMonitor) Then
WScript.Echo strFileToMonitor & " does not exist."
Else
Set objFile1 = objfso.GetFile(strFileToMonitor)
lngSize1 = objFile1.Size
End If
If Not objfso.FileExists(strCurrDir & "\FileSizeMonitor.dat") Then
Set objFileMonitorData = objfso_OpenTextFile(strCurrDir & "\FileSizeMonitor.dat",2,True)
objFileMonitorData.WriteLine lngSize1
objFileMonitorData.Close
Else
Set objFileMonitorData = objfso_OpenTextFile(strCurrDir & "\FileSizeMonitor.dat",1)
strFileMonitorText = objFileMonitorData.ReadLine
lngSize2 = Clng(strFileMonitorText)
objFileMonitorData.Close
Set objFileMonitorData = Nothing
If lngSize1 > lngSize2 Then
Set objFileMonitorData = objfso_OpenTextFile(strCurrDir & "\FileSizeMonitor.dat",2)
objFileMonitorData.WriteLine lngSize1
objFileMonitorData.Close
Set objFileMonitorData = Nothing
Else
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "whatever@email.address"
objEmail.To= "you@email.address"
objEmail.Subject = "Monitored text File unchanged"
objEmail.TextBody = "The file " & strFileToMonitor & " has not changed since the last time it was checked."
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = "change this to smtp server address"
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Set objEmail = Nothing
End If
End If


Set objFile1 = Nothing
Set sFileMonitorData = Nothing
Set objfso = Nothing
Set WshShell = Nothing




---------------------------------------
Bob Beck
Systems Administrator
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top