Kaseya Community

Which then is the script ending on?

  • Im doing a simple script to install java.  The script succeeds at "Then".  Where can I see which Then its stopping on?

    I put in a bunch of steps to send an email in each if/else so I can see what the script is doing but its not sending me any emails.  I do know emailing works as a couple other scripts are working fine.

    Im trying to 1.  Test is java exists on the machine.  If not send and email saying no java on this machine.

    2.  If java exists test if its 8-151 if not install 151.  If it has 151 send an email saying it already has 151.

    Im using /nul to test if a folder exists.  Is this still a valid method?

    Anybody see any glaring errors in this procedure?

    <ScriptExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.kaseya.com/vsa/2008/12/Scripting">
    "); vertical-align: bottom; height: 10px;"><Procedure name="Java Install/Update" treePres="3" id="357663375" folderId="449059111508102" treeFullPath="myProcedures - BW_HD2">
    "); vertical-align: bottom; height: 10px;"><Body description="Install Java">
    "); vertical-align: bottom; height: 10px;"><If description="">
    "); vertical-align: bottom; height: 10px;"><Condition name="TestFile">
    <Parameter xsi:type="StringParameter" name="Path" value="C:\Program Files (x86)\Java\nul"/>
    <Parameter xsi:type="EnumParameter" name="Condition" value="Exists"/>
    <Parameter xsi:type="StringParameter" name="Value" value=""/>
    </Condition>
    "); vertical-align: bottom; height: 10px;"><Then>
    "); vertical-align: bottom; height: 10px;"><If description="">
    "); vertical-align: bottom; height: 10px;"><Condition name="TestFile">
    <Parameter xsi:type="StringParameter" name="Path" value="C:\Program Files (x86)\Java\jre1.8.0_151\nul"/>
    <Parameter xsi:type="EnumParameter" name="Condition" value="NotExists"/>
    <Parameter xsi:type="StringParameter" name="Value" value=""/>
    </Condition>
    "); vertical-align: bottom; height: 10px;"><Then>
    "); vertical-align: bottom; height: 10px;"><Statement name="ExecuteFile" continueOnFail="false">
    <Parameter xsi:type="StringParameter" name="Path" value="\\03sdpbfs01\install\java\JavaSetup8u151.exe"/>
    <Parameter xsi:type="StringParameter" name="Arguments" value="/s MOZILLA=1 IEXPLORER=1"/>
    <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System"/>
    <Parameter xsi:type="BooleanParameter" name="WaitComplete" value="True"/>
    </Statement>
    "); vertical-align: bottom; height: 10px;"><Statement name="WriteScriptLogEntry" continueOnFail="false">
    <Parameter xsi:type="StringParameter" name="Comment" value="Java installed."/>
    </Statement>
    "); vertical-align: bottom; height: 10px;"><Statement name="SendEmail" continueOnFail="false">
    <Parameter xsi:type="StringParameter" name="To" value="yhassell@sandiegoprivatebank.net"/>
    <Parameter xsi:type="StringParameter" name="Subject" value="java installing"/>
    <Parameter xsi:type="MultiLineStringParameter" name="Body" value="installing java"/>
    </Statement>
    </Then>
    "); vertical-align: bottom; height: 10px;"><Else>
    "); vertical-align: bottom; height: 10px;"><Statement name="SendEmail" continueOnFail="false">
    <Parameter xsi:type="StringParameter" name="To" value="yhassell@sandiegoprovatebank.net"/>
    <Parameter xsi:type="StringParameter" name="Subject" value="java 151 already installed"/>
    <Parameter xsi:type="MultiLineStringParameter" name="Body" value="already installed"/>
    </Statement>
    </Else>
    </If>
    </Then>
    "); vertical-align: bottom; height: 10px;"><Else>
    "); vertical-align: bottom; height: 10px;"><Statement name="SendEmail" continueOnFail="false">
    <Parameter xsi:type="StringParameter" name="To" value="yhassell@sandiegoprivatebank.net"/>
    <Parameter xsi:type="StringParameter" name="Subject" value="no java on this device"/>
    <Parameter xsi:type="MultiLineStringParameter" name="Body" value="no java"/>
    </Statement>
    </Else>
    </If>
    </Body>
    </Procedure>
    </ScriptExport>
  • , I don't see anything obvious with the script, but consider putting some "writeProcedureLogEntry" commands at each step so you can trace what is happening.  You can review those in the Agent Procedure log, and try to see what is going on.

    The \nul should work, but if you could identify a real file that should be there, that would be a better test.  I.e. you could dig down to ...\bin\java.exe

  • Thanks Chris.  I did add some writeprocedurelogentry lines and that has helped.  Seems the /nul is working.  I cant dig to a file because  I dont know what version of Java they are currently on and in java's infinite idiotcracy (not sure thats a word) they change the folder name of each new release...

    thanks!

  • note that with continueonfail set to false, your scripts may never complete the logging step, since the script is halted if there's any error, as soon as that error happens.

    to debug, set continueonfail to true.

  • Continue on Fail isn't just for debugging (anymore) :)

    You sometimes need to consider the action you're taking when you set this flag.

    When I create new scripts, I usually set Halt on Fail - but - I look for certain commands that are allowed to fail. For example, I write a default configuration file (halt on fail) then try to write a custom config file to override the default. It may or may not exist. If it doesn't, the writeFile will fail, so I set Continue on Fail for that one command.

    This may not be "good programming", but Kaseya agent procedures don't allow you to check the presence of a file ON the Kaseya server before you copy it - the checks reference the agent file system. Thus, you only have the option to "blind copy". In my example, I halt if the required (default) file isn't copied, but continue merrily on my way if the optional override file isn't copied.

    If I'm struggling with a procedure that doesn't complete, I usually add a writeProcedureLogEntry before and after the suspected command, and enable Continue on Fail for the suspected command(s). As Craig pointed out, you need the Continue on Fail to see any remaining messages in the log.

    You can force a procedure to halt with a failure at a specific point by issuing a getFile command, requesting a file you know doesn't exist (C:\nowhere\nothing.xyz) and setting Halt on Fail. This can be handy in troubleshooting by causing the procedure to stop at specific points in the logic.

    Glenn

  • IT might be failing at the execute procedure step. Does the user have access to the network share where your file is located at?