Kaseya Community

Monitor for presence of recent file

  • I have SQL and ACT database backups that go to individual directories. I'd like to make sure these tasks are running by checking these directories for a recent (within 24 hrs) file. If one exists, I can be fairly confident the backup process is running.

    How can I do this and - I'm relatively new to Kaseya - is there a way to pass a parameter from the monitor so I don't need a custom script for each directory I'm checking?

    Thanks in advance - Joe

    Legacy Forum Name: Monitor for presence of recent file,
    Legacy Posted By Username: jpresto
  • We store the paths to be checked on an agent in the agents registry, so we can use the same scripts on each agent.

    The way we do this is to set a registry key for each backup path such as:
    HKLM\Software\Kaseya\Path1, value c:\myob\myob.dat
    HKLM\Software\Kaseya\Path2, value c:\backup\sqlfile.*
    ..., etc

    Then we have 2 scripts that run, which are basically the same and just set the BackupPath as either Path1 or Path2. Both these scripts then call a generic script that ckecks the BackupPath to make sure it is within 24 hours.

    Legacy Forum Name: Monitor Sets,
    Legacy Posted By Username: eddy@dgs.com.au
  • Thanks for that - what is the process to check that a dir has a recent file in it?

    Legacy Forum Name: Monitor Sets,
    Legacy Posted By Username: jpresto
  • I'm interested in that script also. Did you get a reply already?

    Legacy Forum Name: Monitor Sets,
    Legacy Posted By Username: Daan
  • Daan
    I'm interested in that script also. Did you get a reply already?


    Not bad, just over a year old... you may have taken the resurection post award...

    I would use

    dir | find "fileName.ext"


    Mind you it is case sensitive.

    Legacy Forum Name: Monitor Sets,
    Legacy Posted By Username: thirteentwenty
  • You could do this with a vbScript, pass the folder in as a variable and then loop through.

    -Replace "C:\Test" below with your argument test variable.
    -Replace ".log" with whatever extension of the file you're looking for

    Something like:

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set fsoFolder = CreateObject("Scripting.FileSystemObject")
    daysSinceOldestFileModified = -1
    binFoundFileType = False

    Set currentFolder = fsoFolder.GetFolder("C:\Test")
    Set arrFiles = currentFolder.Files
    For Each currentFile in arrFiles
    'Check if this is a log file
    If InStrRev(currentFile.Name,".log") then
    binFoundFileType = True
    If DateDiff("d",currentFile.DateLastModified,Date) > daysSinceOldestFileModified then
    daysSinceOldestFileModified = DateDiff("d",currentFile.DateLastModified,Date)
    End If
    End If
    Next
    Next

    if False = binFoundFileType then
    Wscript.Echo "Unable to find file of that type."
    elseif daysSinceOldestFileModified
    Wscript.Echo "It appears as if the oldest file was modified in the future."
    elseif True = binFoundLogFile then
    Wscript.Echo daysSinceOldestFileModified
    else
    Wscript.Echo "An unknown error was encountered while checking the date of the oldest Exchange log file."
    end if


    Then your script compares the days to what you want. You could do hours, etc too. I just threw this together, so you might want to tweak it a bit and not just run it right off.

    Legacy Forum Name: Monitor Sets,
    Legacy Posted By Username: Intech-Jason