Return to section contents

Shell Commands:  Quotes and Special Characters

Some consideration is required when defining shell commands within a Management Pack so that quotes and special characters are correctly handled. When a shell command is run by the Operations Manager UNIX/Linux Agent, it is executed by the agent as:  /bin/sh –c “<your shell command>” - where <your shell command> is the command defined in the Management Pack.

Because of the double quotes that wrap the shell command, double quotes in the shell command itself can be problematic. If single quotes are a viable option, it is preferable to use single quotes to double quotes. If double quotes are required, escape the double quote characters with a backslash (\).

A good practice is to test the shell command from a targeted UNIX/Linux host by running the command in a terminal, in the form: /bin/sh –c “<your shell command>”

Additionally, characters that are invalid in XML (<,>, and &) require special handling before embedding in a Management Pack. If these characters are required in your shell command, they should be replaced with their HTML equivalents prior to input in the Management Pack:
  • < becomes &lt;
  • > becomes  &gt;
  • & becomes &amp;

To easily test formatting of your shell command, the Run a UNIX/Linux Shell Command task template can be used to create and test a shell command in the Operations Console. This template is available in the Operations Console’s Authoring Pane, under Management Pack Objects, Tasks, Create a New Task.

Scripts: Special Characters

Shell scripts and PowerShell scripts contained within Management Packs should be contained within CDATA blocks so that characters that are invalid in XML (<,>, and &) are correctly handled.

For example:

    echo $1