date adn time of oldest file

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
Troy.Ryan
Posts: 5
Joined: Tue Oct 09, 2007 7:24 am

date adn time of oldest file

Post by Troy.Ryan »

Sometime i feel really stupid :oops: but here it goes.

How do i setup a test to email be the date and time of the oldest file in a folder? I bet it's simple but I'm not having any luck.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Just setup Folder/File availability tests with %OldestFile% macro variable.
E.g. File of Folder name:
C:\data\%OldestFile%
Do not forget to enable "Translate macros" option.
Also enable "Tune Up reply value" option with variable: %FileTime%
Send e-mail (SMTP) action, assigned to this test item, should have mail template with %Reply% macro variable - it will contain date and time of oldest file.


Please check the manual or visit our web site for more information at:
File specific macro variables: http://www.ks-soft.net/hostmon.eng/mfra ... especmacro
Test specific macro variables: http://www.ks-soft.net/hostmon.eng/mfra ... ificmacros
Troy.Ryan
Posts: 5
Joined: Tue Oct 09, 2007 7:24 am

Post by Troy.Ryan »

Awesome thanks for the reply. I understand what you posted and i understand how the "Tune Up reply value" does and have read about it in the manual. However I cant figure out where to set that up. Where is it?
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

"Tune Up reply value" option is located on bottom of Test properties dialog (Optional status processing section).
This option can be hidden. Just click on [+] icon above the "Help" button.

Actually "Tune Up reply value" option is not necessary in this case.
You may simply use %FileTime% macro variable in mail template of Send e-mail (SMTP) action.
Troy.Ryan
Posts: 5
Joined: Tue Oct 09, 2007 7:24 am

Post by Troy.Ryan »

Wow never saw those options :D

So its working except for one thing. It shows me the oldest file (that's what i asked for) but i nee the oldest file that matches OH*.txt.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

In such case you will need to use Shell Script test with custom made script.
E.g. you may use VB script like the following:

Code: Select all

Option Explicit
On Error Resume Next

const statusUnknown     = "scriptRes:Unknown:"
const statusOk          = "scriptRes:Ok:"
const statusBad         = "scriptRes:Bad:"

dim Fso, Folder, File, Path, objArgs, Wildcard, WA, p1, p2, oldest, objFile, k
Set objArgs = WScript.Arguments

if objArgs.Count < 1 then
 WScript.StdOut.Write statusUnknown & "Expected parameters <Path\File Wildcard> E.g.: C:\logfiles\KN*.txt"
 Wscript.Quit
end if

Path = objArgs(0)
WA = split(Path,"\")
Wildcard = WA(UBound(WA))
Path = ""

for k = Lbound(WA) to UBound(WA)-1
  Path = Path & WA(k) & "\"
next

WA = split(Wildcard,"*")
p1 = WA(0)
p2 = WA(1)

Set fso = CreateObject("Scripting.FileSystemObject")
Set Folder = fso.getfolder(Path)

for Each File in Folder.Files
  if (InStr(1, fso.GetFileName(File), p1, vbTextCompare) = 1) AND (InStr(1, fso.GetFileName(File), p2, vbTextCompare) > 0 ) then
  Set objFile = fso.GetFile(File)
    if oldest = "" then
    Set oldest = objFile
    else
      if objFile.DateLastModified < oldest.DateLastModified then Set oldest = objFile end if
    end if
  end if
next

if oldest="" then
  WScript.StdOut.Write statusOk & "no files found"
 else
  WScript.StdOut.Write statusBad & oldest.DateLastModified & " (" & oldest.Name & ")"
end if
Start CMD: cmd /c cscript /B /E:VBScript %Script% %Params%

This script requires one parameter - path with file wildcard.
Parameter examples:
C:\logfiles\KN*.txt
C:\logfiles\*.txt
C:\logfiles\*.*
C:\logfiles\KN*
Post Reply