Kaseya Community

Write very complex shell command output to file (MAC OS X)

This question is not answered

Hello people,

First of all this week i did the official Kaseya training and it was really awesome and i learned a lot!

Now on topic!
i am trying to execute a complex shell command on Mac OS X.

Shell Command
ioreg -l | awk '/IOPlatformSerialNumber/ { split($0, line, "\""); printf("%s\n", line[4]); }' >> #awd#/naam.txt

#awd# is the variable for the agent working directory and naam.txt is  the text file has a sentence with my macs serial number. It fails to grep the output and put it in the file.

 

Is this shell command to complex for Kaseya?

edit:

.xml file

<?xml version="1.0" encoding="utf-8"?>

<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">

  <Procedure name="Verander naam MAC Serienummer" treePres="3" id="951312739">

    <Body description="naam veranderen van de MAC unbinden OD + AD en daarna weer binden aan het AD.&#xA;&#xA;ComputerName&#xA;LocalHostName&#xA;HostName">

      <Statement description="Create a named procedure variable and assign a value retrieved from the managed machine by the agent." name="GetVariable" continueOnFail="false" osType="MacOS">

        <Parameter xsi:type="EnumParameter" name="VariableType" value="AgentTempDirectory" />

        <Parameter xsi:type="StringParameter" name="SourceContent" value="" />

        <Parameter xsi:type="StringParameter" name="VariableName" value="awd" />

      </Statement>

      <Statement description="Execute the given command as if it were typed in at a command prompt." name="ExecuteShellCommand" continueOnFail="false" osType="MacOS">

        <Parameter xsi:type="StringParameter" name="Command" value="ioreg -l | awk '/IOPlatformSerialNumber/ { split($0, line, &quot;\&quot;&quot;); printf(&quot;%s\n&quot;, line[4]); }' &gt;&gt; #awd#/macnaam.txt" />

        <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

        <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

      </Statement>

      <Statement description="Create a named procedure variable and assign a value retrieved from the managed machine by the agent." name="GetVariable" continueOnFail="false" osType="MacOS">

        <Parameter xsi:type="EnumParameter" name="VariableType" value="FileContent" />

        <Parameter xsi:type="StringParameter" name="SourceContent" value="#awd#/macnaam.txt" />

        <Parameter xsi:type="StringParameter" name="VariableName" value="#naam#" />

      </Statement>

      <Statement description="Execute the given command as if it were typed in at a command prompt." name="ExecuteShellCommand" continueOnFail="false" osType="MacOS">

        <Parameter xsi:type="StringParameter" name="Command" value="scutil --set ComputerName #naam#" />

        <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

        <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

      </Statement>

      <Statement description="Execute the given command as if it were typed in at a command prompt." name="ExecuteShellCommand" continueOnFail="false" osType="MacOS">

        <Parameter xsi:type="StringParameter" name="Command" value="scutil --set LocalHostName #naam#" />

        <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

        <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

      </Statement>

      <Statement description="Execute the given command as if it were typed in at a command prompt." name="ExecuteShellCommand" continueOnFail="false" osType="MacOS">

        <Parameter xsi:type="StringParameter" name="Command" value="scutil --set HostName #naam#" />

        <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

        <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

      </Statement>

    </Body>

  </Procedure>

</ScriptExport>

 

 



[edited by: Jack Dekker at 12:09 PM (GMT -7) on 4-15-2011] xml file added
All Replies
  • The problem is going to related to special characters that will need to be escaped. I'll dig up some examples I have of this for OS X and post them later today or this weekend as well as put some time into trying to get this particular line to work through Kaseya.

  • Thanks Ben!

  • Any documentation on this yet? tnx!

  • Hey Jack,

    community.kaseya.com/.../3458.aspx

    Click that link, import the procedure, and edit it.

    That is probably one of the most complex procedures I've put together, so I think you'll learn plenty from it. Scroll down and you'll see a section where I dynamically build a text file for OS X and you will see how I have to escape certain characters when doing so.

  • Thanks so much i will try it out tomorrow on my lab machine.