File Age
|
Logged in as: Guest
|
|
Users viewing this topic:
none
|
|
Login | |
|
File Age - 10.Mar.2004 3:17:00 AM
|
|
|
kieran
Posts: 1
Joined: 8.Mar.2004
Status: offline
|
How similar are GFI Server Monitor and Alchemy Eye (http://www.alchemy-lab.com/products/eye/)
We'd like to migrate from Alchemy Eye over to Server Monitor but there are a few things stopping us.
Does anyone know of a way of being able return the age of a file so we can alert if a filestamp is too old?
|
|
|
|
RE: File Age - 13.Mar.2004 1:25:00 PM
|
|
|
Nicks
Posts: 2605
Joined: 17.Mar.2003
Status: offline
|
GFI Network Server monitor has similar functionality to Alchemy Eye, with a few extra checks (e.g. support for RSH scripts and SNMP)
However, it does not have a check that checks the date of a file. You would have to write (or find on the internet) a script that performs this job.
Check the scripting section on the GFI web site (http://www.gfi.com/nsm/scripting/)
|
|
|
|
RE: File Age - 25.Jun.2008 2:50:52 PM
|
|
|
trwagner1
Posts: 30
Joined: 24.Aug.2006
Status: offline
|
Has anyone successfully written a VB script to do just this? Evaluate a directory for a file age? I have a stand-alone VB script that I can pass arguments to that works. However, I need advice on how to modify this so I can use it in GFI. I don't see many examples of how return values are expected from running either a command-line program or using functions. I would like to pass the %CHECK_DESCRIPTION% value to the function, but so far I've not had any luck getting my script to work. Does anyone have any experience here to offer advice? My script has two functions. One function compares the file.datelastmodified to the current date now(). The second function in the script executes a directory listing so that the first function can do the date comparisons. So far, the help file, documentation, and examples I've seen aren't helping me. Thanks Ted
|
|
|
|
RE: File Age - 26.Jun.2008 10:59:50 AM
|
|
|
trwagner1
Posts: 30
Joined: 24.Aug.2006
Status: offline
|
I believe I have a solution to this. I'll post the answer soon. Ted
|
|
|
|
SOLUTION: Monitor Function to Check for old Files - 26.Jun.2008 11:18:28 AM
|
|
|
trwagner1
Posts: 30
Joined: 24.Aug.2006
Status: offline
|
Here's a vbscript that will scan UNC path OR local path for "old files". Age deteremined by varFileAgeCheck in script. Modify explanation if you so desire. I added them for debugging with the monitor now option from the GUI. Instructions: Save attached vb script to script directory. Adjust varFileAgeCheck in script. varFileAgeCheck is in minutes. Add monitor check. Select Generic VB Script. Browse and select the vb script saved above. VB Function to execute... value is: CheckFileAge Double click parameter 1. Parameter value should be the path to the directory you wish to check; the value should be enclosed in double quotes. Example "C:\TEMP" or "\\Server\Share\Folder" Add description if desired. Complete monitor check creation.
' /////////////////////////////////////////////////////////////////////////////
Option Explicit
' This monitor function checks for files older than 5 minutes in the directory specified in
' the first parameter value of the vbscript monitor.
' change value varFileAgeCheck to adjust value by minutes.
Const retvalUnknown = 1
Function CheckFileAge(strDirName)
On Error Resume Next
Dim objFSO, objFolder, objContents, objFile, objFileDate1, objFileDate2, varDateDiff, varFileAgeCheck
' Set FileSystemObject and get directory listing
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strDirName)
Set objContents = objFolder.Files
varFileAgeCheck = 5
' Compare each file's create/modify date & time to current date & time.
For Each objFile in objContents
objFileDate1 = objFile.DateLastModified
objFileDate2 = Now()
varDateDiff = Abs(DateDiff("n",objFileDate2,objFileDate1))
If DateDiff("n", objFileDate1, Now) > varFileAgeCheck then
' Check for files older than 5 minutes. Return FALSE to signify monitor failure
EXPLANATION = objFile & " is older than 5 minutes."
CheckFileAge = FALSE
' as soon as condition exists, that's all we need to signify monitor failure. Exit function.
Exit Function
End If
Next
' Return TRUE to signify monitor success for no files found.
EXPLANATION = "No files older than 5 minutes in directory " & strDirName
CheckFileAge = TRUE
End Function
|
|
|
|
RE: SOLUTION: Monitor Function to Check for old Files - 8.Jul.2008 4:24:36 AM
|
|
|
MRIS
Posts: 2
Joined: 8.Jul.2008
Status: offline
|
trwagner1's solution to this is excellent. However I had already solved a problem similar to this with the following script. I'm not saying this script is better, it's just another way. This script is different in two ways. The first difference is that it checks an actual specific file, rather than a folder. The second difference is that it accepts the number of hours as one of the script arguments, allowing the same script to be re-used in multiple checks. For example one check may test if a file is older than, say 1 hour, and another check may check if another file is say, 24 hours old.
' /////////////////////////////////////////////////////////////////////////////
' Accepts 2 parameters
' First parameter is the UNC path of the file, eg "\\server\path\file.txt"
' Second parameter is the age in hours
' the check reports success if the age in hours of the file is newer than this number.
' /////////////////////////////////////////////////////////////////////////////
Option Explicit
Const retvalUnknown = 1
Function IsFileNewerThanHours(TheFile,Hours)
' This file designed, created, tested and deployed by MRIS
On Error Resume Next
Dim fso, f, FileDateCreated, AgeInHours
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(TheFile)
FileDateCreated = f.DateLastModified
AgeInHours = DateDiff("h",FileDateCreated,Now)
If AgeInHours > Hours then
EXPLANATION = TheFile & " is " & AgeInHours & " hours old, which is more than " & Hours & " hours."
IsFileNewerThanHours = False
End If
If AgeInHours <= Hours then
EXPLANATION = TheFile & " is " & AgeInHours & " hours old, which is less than " & Hours & " hours."
IsFileNewerThanHours = True
End If
End Function
< Message edited by MRIS -- 8.Jul.2008 4:30:08 AM >
|
|
|
|
RE: SOLUTION: Monitor Function to Check for old Files - 8.Jul.2008 7:11:34 AM
|
|
|
trwagner1
Posts: 30
Joined: 24.Aug.2006
Status: offline
|
Excellent! Thanks. I have further refined mine similar to yours so that it's checking files with a specific extension in a specific directory (both the unc path and the file extension used as arguments). Very similar to yours. This is good stuff. I've redued my false positives on directory checks by almost 90% by using this type of check versus just the existence or lack of existence of a file. Ted
|
|
|
|
RE: SOLUTION: Monitor Function to Check for old Files - 21.Aug.2008 8:51:44 AM
|
|
|
Boydy
Posts: 6
Joined: 5.Aug.2008
Status: offline
|
Hi All, I'm after something similar however I would like to scan a directory for files over a certain size! Can this done with VB Script? I'm a total beginner with VB Script so any help would be much appreciated! Thanks in advance, Kirk
|
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|