Kaseya Community

The IF statement is flawed

  • MadI am trying to do a SQL database integrity check which is then outputted to a text log file. That has been the easy bit, I try to use the IF statement as follows.

    IF
    #content#
    contains 0 allocation errors and 0 consistency errors
    then...


    except that the "0 allocation errors and 0 consistency errors" appears 3 times in the log file. Is there a way of making a statement that
    IF there is anywhere in the file that contains a value higher than 0 allocation errors and 0 consistency errors it will then continue the script, Else it will write a log entry.

    Legacy Forum Name: The IF statement is flawed,
    Legacy Posted By Username: dsheedy
  • I've had this same issue. To work around this I use the IF statement and check the file content and point it to the file itself.

    Using variables in the file path/name seems to work OK (eg #AgentTemp#\logfile.txt, or #LogFileLocation#)

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: eddy@dgs.com.au
  • eddy@dgs.com.au
    I've had this same issue. To work around this I use the IF statement and check the file content and point it to the file itself.

    Using variables in the file path/name seems to work OK (eg #AgentTemp#\logfile.txt, or #LogFileLocation#)




    I am not sure if you understood my issue. The issue is when i check for errors in the log file it reports 0 because in the log file it contains "0 allocation errors and 0 consistency errors" 3 times in the file.

    If i use the IF Contains statement with "0 allocation errors and 0 consistency errors" it will always be the same if only one of those 3 times it is mentioned stated 0 "allocation errors and 0 consistency errors"

    for example

    0 allocation errors and 0 consistency errors
    0 allocation errors and 1 consistency errors
    0 allocation errors and 0 consistency errors

    "IF c:\log.txt CONTAINS "0 allocation errors and 0 consistency errors"

    It will always contain that string even if in another part it has an error.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: dsheedy
  • dsheedy

    I have run into this same issue with other output test/log files. And have not (yet) found a workaround. In our SMART Disk Check script, we were able to look for the text "FAILED!", which would appear at the top of the file if any of the detailed checks reported "FAILED" - without the exclaimation mark. So we were okay for that one.

    Lloyd

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: lwolf
  • Before you get to the IF statement in the 2nd script do the following shell command in the 1st script.

    FIND /C "0 allocation errors and 0 consistency errors" C:\somelog.txt >> C:\temp\results.txt

    Get the contents of results.txt as a variable to use inthe 2nd scripts IF statement.

    If the content does not contain "3" then something is up.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: T2Craig
  • Craig,

    Wow, that sounds like an excellent workaround !

    Lloyd

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