Expansion of command line elements

The <Command>, <Stdin> and <Argument> elements support special sequences that are expanded by the AIX® Runtime Expert framework to produce the final command lines.

The table below is a short reference of all the supported sequences. For more details on a sequence, refer to the sections below.

Table 1. Sequence
Sequence Expands to
%% The literal % character.
%a The concatenation of the expanded Argument strings for all parameters that can be processed in the same command line.
%n The name of the parameter.
%v1 The value of the parameter.
%v2 The second value of the parameter. Only valid for diff operations.
%f1 The name of the temporary file that will contain the value of the parameter.
%f2 The name of the temporary file that will contain the second value of the parameter. Only valid for diff operations.
%v1[name] The value of parameter name.
%v2[name] The second value of parameter name. Only valid for diff operations.
%f1[name] The name of a temporary file that will contain the value of the parameter name.
%f2[name] The name of a temporary file that will contain the second value of parameter name. Only valid for diff operations.
%t[class] The name of the target instance for the target class.
%p[name] The value of property name.
%c The catalog id.

Escaping of % sequences

Parameter names, parameter values and target names that are expanded by the AIX Runtime Expert are enclosed between single quotes when they are used inside a <Command> element or inside an <Argument> element that is to be inserted (via the %a sequence) into a <Command> element. This is to ensure that those strings will be passed to the shell as a single word, even if they include spaces or other special characters. Additionally, any single quote character within the expanded expression is properly escaped.

The catalog writers must be careful to not use the %n, %v1, %v2, %v1[name], %v2[name] or %t[class] sequences inside a quoted string. If those sequences must be used within a string, the string must be closed before the % sequence as shown in the following example:
echo "Parameter "%n" is set to "%v1

Failure to do so will result in incorrect command lines and is a security risk.

The %% sequence

The %% sequence expands to the literal % character.

For example, the string:

/bin/ps -aeF"%%a"

expands to the following string:

/bin/ps -aeF"%a"

The %a sequence

The %a sequence can be used either in the <Command> string, or in the <Stdin> string. It is substituted with the concatenation of all the expanded <Argument> strings of all the parameters that can be treated in the same command (see the Command line generation topic for a formal description on parameter grouping).

For example, the following catalog (note that it could be simplified by using the %n sequence) :

<CfgMethod id=”vmo”>
  <Get type=”current”
    <Command>/usr/sbin/vmo%a</Command>
  </Get>
</CfgMethod>
<ParameterDef name=”lgpg_size” cfgmethod=”vmo”>
  <Get type=”current”>
    <Argument> -o lgpg_size</Argument>
  </Get>
</ParameterDef>
<ParameterDef name=”lgpg_regions” cfgmethod=”vmo”>
  <Get type=”current”>
    <Argument> -o lgpg_regions</Argument>
  </Get>
</ParameterDef>

And the following profile:

<Parameter name=”lgpg_size” />
<Parameter name=”lgpg_regions” />

will produce the following command line for the “get current” operation:

/usr/sbin/vmo –o lgpg_size –o lgpg_regions

The %n sequence

The %n sequence is substituted with the name of the parameter.

Using the %n sequence, the example from the %a section could be simplified as follows:

<CfgMethod id=”vmo”>
<Get type=”current”>
    <Command>/usr/sbin/vmo%a</Command>
    <Argument> -o %n</Argument>
</Get>
</CfgMethod>
<ParameterDef name=”lgpg_size” cfgmethod=”vmo” />
<ParameterDef name=”lgpg_regions” cfgmethod=”vmo” />

With the following profile:

<Parameter name=”lgpg_size” />
<Parameter name=”lgpg_regions” />

The following command line would be generated for the get current operation:

/usr/sbin/vmo –o ’lgpg_size’ –o ’lgpg_regions’

The %v1 and %v2 sequences

The %v1 sequence is substituted with the value of the parameter.

The %v2 sequence is only valid for <Diff> operations and is substituted with the second value of the parameter.

For example, the following catalog:

<CfgMethod id=”vmo”>
  <Set type=”permanent”>
    <Command>/usr/sbin/vmo -p%a</Command>
    <Argument> -o %n=%v1</Argument>
  </Set>
</CfgMethod>
<ParameterDef name=”lgpg_size” cfgmethod=”vmo” />
<ParameterDef name=”lgpg_regions” cfgmethod=”vmo” />

with the following profile:

<Parameter name=”lgpg_size” value=”16M”/>
<Parameter name=”lgpg_regions” value=”128” />

would generate the following command line for the set permanent operation:

/usr/sbin/vmo –p –o ’lgpg_size’=’16M’ –o ’lgpg_regions’=’128’

The %f1 and %f2 sequences

The %f1 and %f2 sequences are substituted with the name of temporary file created before the command is executed. The file content is the value of the parameter for %f1 and the second value of the parameter for %f2. The %f2 sequence can only be used for <Diff> operations.

For example, the following catalog:

<ParameterDef name=”some_file”>
  <Diff>
    <Command>/usr/bin/diff %f1 %f2</Command>
  </Diff>
</ParameterDef>

When an artexdiff is performed between the two profiles including the same parameter with a different value:

<Parameter name=”some_file” value=”foo” />
<Parameter name=”some_file” value=”bar” />

Then two temporary files /tmp/file1 and /tmp/file2 (actual file names will be different) containing respectively the “foo” and “bar” strings will be created, and the following command will be executed:

/usr/bin/diff /tmp/file1 /tmp/file2

The %v1[name] and %v2[name] sequences

The %v1[name] sequence is substituted with the value of parameter name.

The %v2[name] sequence is only valid for <Diff> operations and is substituted with the second value of parameter name.

Those sequences are useful when a configuration command accepts several parameters at the same time, but require that some of them be placed in a particular position on the command line. This is the case of the chcons command for example, which requires that the path to the console device or file come last on the command line. Using the %v1[name] sequence, the chcons catalog could be written as follows:

<CfgMethod id=”chcons”>
  <Set type=”nextboot”>
    <Command>/usr/sbin/chcons%a %v1[console_device]</Command>
    <Argument> -a %n=%v1</Argument>
  </Set>
</CfgMethod>
<ParameterDef name=”console_device” cfgmethod=”chcons” reboot=”true” />
<ParameterDef name=”console_logname” cfgmethod=”chcons” reboot=”true” />
<ParameterDef name=”console_logsize” cfgmethod=”chcons” reboot=”true” />

with the following profile:

<Parameter name=”console_device” value=”/dev/vty0”/>
<Parameter name=”console_logname” value=”/var/adm/ras/conslog” />
<Parameter name=”console_logverb” value=”9” />

This catalog would generate the following command line for the set nextboot operation:

/usr/sbin/chcons –a ’console_logname’=’/var/adm/ras/conslog’ –a ’console_logverb’=’9’ /dev/vty0

The %f1[name] and %f2[name] sequences

The %f1[name] and %f2[name] sequences are substituted with the name of temporary file created before the command is executed. The file content is the value of parameter name for %f1[name] and the second value of parameter name for %f2[name]. The %f2[name] sequence can only be used for <Diff> operations.

The %t[class] sequences

The %t[class] sequence is substituted with the name of the target instance being treated for target class.

The %t[class] sequence is used for parameters that apply to a specific object, not to the whole system. An example of this is the chuser command, whose parameters apply to a specific user (root, guest) for a specific registry (files, LDAP). The catalog for the chuser command could be written as follows:

<CfgMethod id=”chuser”>
  <Set type=”permanent”>
<Command>/usr/bin/chuser –R %t[module]%a %t[user]</Command>
    <Argument> %n=%v1</Argument>
  </Set>
</CfgMethod>
<ParameterDef name=”shell” cfgmethod=”chuser” targetClass=”module,user”>
<ParameterDef name=”histsize” cfgmethod=”chuser” targetClass=”module,user” />

With the following profile, which sets the shell and histsize parameters for users adam and bob in the LDAP and files registries:

<Parameter name=”shell” value=”/usr/bin/ksh”>
  <Target class=”module” instance=”LDAP” />
  <Target class=”user” instance=”adam” />
</Parameter>
<Parameter name=”histsize” value=”5000”>
  <Target class=”module” instance=”LDAP” />
  <Target class=”user” instance=”adam” />
</Parameter>
<Parameter name=”shell” value=”/usr/bin/ksh”>
  <Target class=”module” instance=”files” />
  <Target class=”user” instance=”adam” />
</Parameter>
<Parameter name=”histsize” value=”5000”>
  <Target class=”module” instance=”files” />
  <Target class=”user” instance=”adam” />
</Parameter>
<Parameter name=”shell” value=”/usr/bin/bash”>
  <Target class=”module” instance=”LDAP” />
  <Target class=”user” instance=”bob” />
</Parameter>
<Parameter name=”histsize” value=”10000”>
  <Target class=”module” instance=”LDAP” />
  <Target class=”user” instance=”bob” />
</Parameter>
<Parameter name=”shell” value=”/usr/bin/bash”>
  <Target class=”module” instance=”files” />
  <Target class=”user” instance=”bob” />
</Parameter>
<Parameter name=”histsize” value=”10000”>
  <Target class=”module” instance=”files” />
  <Target class=”user” instance=”bob” />
</Parameter>

It would execute the following commands:

/usr/bin/chuser –R ’LDAP’ ’shell’=’/usr/bin/ksh’ ’histsize’=’5000’ ’adam’
/usr/bin/chuser –R ’files’ ’shell’=’/usr/bin/ksh’ ’histsize’=’5000’ ’adam’
/usr/bin/chuser –R ’LDAP’ ’shell’=’/usr/bin/bash’ ’histsize’=’10000’ ’bob’
/usr/bin/chuser –R ’files’ ’shell’=’/usr/bin/bash’ ’histsize’=’10000’ ’bob’

Notice how four commands were generated. The reason is that the %t[module] and %t[user] sequences were used in the <Command> string, meaning that each command is specific to a particular module and user. Because of this, only parameters that apply to the same module and user are grouped together.

The %p[name] sequence

The %p[name] sequence is substituted with the value specified in the input profile for property name. For example, the following prerequisite uses the %p[nodeId] sequence to check that the node id of the local system (returned by the uname –f command) matches the node id stored in the nodeId property of the profile:
<PrereqDef id="nodeId">
  <Command>[[ `/usr/bin/uname -f` = %p[nodeId] ]]</Command>
  <ErrMessage>Parameter cannot be applied to a different node</ErrMessage>
</PrereqDef>

The %c sequence

The %c sequence is substituted with the id of the catalog file that the parameter belongs to. This is the catalog id specified in the profile, which can be different from the id of the catalog that actually defines the parameter if catalog inheritance is used.

For example, the following prerequisite uses the %c sequence to check that the uniquetype of the target device matches the name of the catalog file:
<PrereqDef id="devUniqueType">
  <Command>[[ "devParam.`/usr/sbin/lsdev -F uniquetype -l %t[device] | /usr/bin/tr / .`" = %c ]]</Command>
  <ErrMessage>Parameter cannot be applied to a different device type</ErrMessage>
</PrereqDef>