Kaseya Community

Script to check file attributes

  • Hi All,

    I need a script which can check specific files/folders and their attributes.

    I think need a script which runs after this to check if anything has changed since the previous script run...

    Does anyone know of anything out there like this?


    Thanks in advance
    Neal

    Legacy Forum Name: Script to check file attributes,
    Legacy Posted By Username: goodane1
  • Neal,

    Try using these in a command shell.

    http://www.windowsvistauserguide.com/command_line/command_line_dir.htm

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: trnetwork
  • goodane1
    Hi All,

    I need a script which can check specific files/folders and their attributes.

    I think need a script which runs after this to check if anything has changed since the previous script run...

    Does anyone know of anything out there like this?


    Thanks in advance
    Neal


    Have a play with this basic script:

    Script Name: test backup
    Script Description: Get file attributes - get results - add to machines docs - alert if file contents change. - carey-pccare Sept 09 - In step 1 change the path to the folder you want to monitor and the location of the results.txt file. In step 3 change the path to point to the results.txt file.



    IF True
    THEN
    Execute Shell Command
    Parameter 1 : dir c:\testbackup >>c:\test\results.txt
    Parameter 2 : 0
    OS Type : 0
    Get File
    Parameter 1 : c:\test\results.txt
    Parameter 2 : ..\Docs\results.txt
    Parameter 3 : 0
    OS Type : 0
    ELSE

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: carey-pccare
  • [QUOTE=carey-pccare;46764]Have a play with this basic script:

    Script Name: test backup
    Script Description: Get file attributes - get results - add to machines docs - alert if file contents change. - carey-pccare Sept 09 - In step 1 change the path to the folder you want to monitor and the location of the results.txt file. In step 3 change the path to point to the results.txt file.



    IF True
    THEN
    Execute Shell Command
    Parameter 1 : dir c:\testbackup >>c:\test\results.txt
    Parameter 2 : 0
    OS Type : 0
    Get File
    Parameter 1 : c:\test\results.txt
    Parameter 2 : ..\Docs\results.txt
    Parameter 3 : 0
    OS Type : 0
    ELSE[/QUOTE]

    How does this alert if the file contents/atts change?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: goodane1
  • change alerts.JPG
    goodane1
    How does this alert if the file contents/atts change?


    In the script - the last step is get file, and there is an option to alert if file changes. see attached.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: carey-pccare
  • **EDIT** answered my questions....however another gets posed.

    Here's the situation. We have software that creates an SQL database every night. We want to look at the modified date and send an error when it hasn't been modified in the past X amount of days.

    I'm still searching for a solution. I'll post when and if I got one

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: icrook
  • Create a scheduled kaseya script that starts with a VBS script to get the file attributes (ie last modified date), and writes to a text file if over a certain age. Follow up with a "Get File" step that sends an alert if the text file changes.

    Here's a sample VBS script (also includes a number of file attribute variables that you can keep an eye on)

    on error resume next

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.GetFile("c:\temp\mybackup.bak")

    'Optional Attributes
    '-----------------------------------------------------------------
    'Wscript.Echo "Date created: " & objFile.DateCreated
    'Wscript.Echo "Date last accessed: " & objFile.DateLastAccessed
    'Wscript.Echo "Date last modified: " & objFile.DateLastModified
    'Wscript.Echo "Drive: " & objFile.Drive
    'Wscript.Echo "Name: " & objFile.Name
    'Wscript.Echo "Parent folder: " & objFile.ParentFolder
    'Wscript.Echo "Path: " & objFile.Path
    'Wscript.Echo "Short name: " & objFile.ShortName
    'Wscript.Echo "Short path: " & objFile.ShortPath
    'Wscript.Echo "Size: " & objFile.Size
    'Wscript.Echo "Type: " & objFile.Type


    'Write alert to file if last modified date is greater than x days
    '-----------------------------------------------------------------
    dim sFileAge, sTxtFile, sMessage
    sFileAge = DateDiff("d", objFile.DateLastModified, NOw)
    sMessage = "Alert entry " & Now & ". " & objFile & _
    " last modified on " & objFile.DateLastModified & _
    " is older than x days."

    if sFileAge >3 then
    Set sTxtFile = objFSO.OpenTextFile("c:\temp\results.txt", 8, True)
    sTxtFile.WriteLine(sMessage)
    sTxtFile.Close
    end if

    wscript.quit


    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Gavin