Announcement

Collapse
No announcement yet.

Mom 2005 script / Check on file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mom 2005 script / Check on file

    Dear Experts,

    Is there someone who can help me setup a small script in MOM 2005.

    This script should send an event if a specific file on a server 2003 network share is aged longer then 10 minutes.

    After some research on one of the great resources on the net i came up with this script. But i need to adjust to check only one file in stead.

    Moderator edit: Wrapped [CODE]-tags around the code
    Code:
    Dim fs, file, s, objFolder, FileAgeThreshold 
    'Constants
    Const EVENT_TYPE_ERROR       = 1
    Const EVENT_TYPE_WARNING     = 2
    Const EVENT_TYPE_INFORMATION = 4
    
    Set objAPI = CreateObject("MOM.ScriptAPI")
    
    Set objParameters = WScript.Arguments
    FolderName = objParameters(0) 
    FileAgeThreshold = int(objParameters(1)) 
    'TargetFolder = "d:\logs\" 
    TargetFolder = objParameters(0)
    wscript.echo TargetFolder
    
    Set objShell = CreateObject("Shell.Application")
    Set fs = CreateObject("Scripting.FileSystemObject") 
    Set objFolder = objShell.Namespace(TargetFolder) 
    Set colItems = objFolder.Items
    
    If Err.Number > 0 Then
       Call objAPI.LogScriptEvent("MultFileAge.vbs ",4461, EVENT_TYPE_ERROR   ,"Folder " & FolderName & " was not found.")
    
    ELSE 
       For i = 0 to colItems.Count - 1
         filespec=colItems.Item(i)
         Set file = fs.GetFile(TargetFolder & filespec) 
         FileDateLastMod = file.DateLastModified
    
         'Raises an alert for the first
         IF DateDiff("n", FileDateLastMod, Now) < FileAgeThreshold then 
           Call objAPI.LogScriptEvent("MultFileAge.vbs ",4464, EVENT_TYPE_INFORMATION   ,"File " & File & " was last modified on " & FileDateLastMod & ". This last modified date is newer than the error threshold of " & FileAgeThreshold & " minutes.")
         ELSE
           Call objAPI.LogScriptEvent("MultFileAge.vbs ",4465, EVENT_TYPE_ERROR   ,"File " & File & " was last modified at " & FileDateLastMod & ". This is older than the error threshold of " & FileAgeThreshold & " minutes.")
           Wscript.Quit 
         END IF 
       Next
    
    END IF
    Is there someone who can help me with this? Many thanks in advance.
    Last edited by Rems; 19th August 2009, 14:07.

  • #2
    Re: Mom 2005 script / Check on file

    Originally posted by Carlson View Post
    i need to adjust to check only one file in stead.
    Let's just remove the iteration loop and add some parameter checking too. The MOM parts are removed, but I'm sure you can add them.

    Code:
    option explicit
    
    Dim fs, file, objFolder, FileAgeThreshold 
    dim fileToCheck, objParameters, TargetFolder, objShell, FileDateLastMod
    
    'Constants
    Const EVENT_TYPE_ERROR       = 1
    Const EVENT_TYPE_WARNING     = 2
    Const EVENT_TYPE_INFORMATION = 4
    
    
    Set objParameters = WScript.Arguments
    
    if( objParameters.count <> 3) then
        wscript.echo "parameter count mismatch"
        wscript.quit
    end if
    
    TargetFolder = objParameters(0)
    FileAgeThreshold = int(objParameters(1)) 
    fileTocheck = objParameters(2)
    
    
    
    Set objShell = CreateObject("Shell.Application")
    Set fs = CreateObject("Scripting.FileSystemObject") 
    
    If Err.Number > 0 Then
       ' some log code
    
    ELSE 
         Set file = fs.GetFile(TargetFolder & fileToCheck) 
         FileDateLastMod = file.DateLastModified
    
         'Raises an alert for the first
         IF DateDiff("n", FileDateLastMod, Now) < FileAgeThreshold then 
           ' some log code
            wscript.echo "new file"
         ELSE
           wscript.echo "old file"
           Wscript.Quit 
         END IF 
    END IF
    -vP

    Comment


    • #3
      Re: Mom 2005 script / Check on file

      Thank you very much. I will test it first thing in the morning and let you know...

      Is this where i can configure the file, folder and treshold settings?

      TargetFolder = objParameters(0)
      FileAgeThreshold = int(objParameters(1))
      fileTocheck = objParameters(2)
      Last edited by Carlson; 19th August 2009, 20:47.

      Comment


      • #4
        Re: Mom 2005 script / Check on file

        Originally posted by Carlson View Post
        Is this where i can configure the file, folder and treshold settings?

        TargetFolder = objParameters(0)
        FileAgeThreshold = int(objParameters(1))
        fileTocheck = objParameters(2)
        Those settings are read from command line arguments. So if you want to hard-code the values, just replace objParameters array access with values. Personally, I'd rather put the values into a config file or read them from the command line like the case already is.

        -vP

        Comment

        Working...
        X