Previous Topic: localNext Topic: pipe


batch

The batch interface of the CLI is invoked by specifying the “batch” keyword . In this case, the CLI expects a file name (filename) separated by at least one blank from the “batch” keyword. This file name could either be an absolute file name or a relative one. It identifies a file containing a list of CLI commands to be executed by this call.

The CLI processes the batch file as follows:

  1. It establishes a session to the specified manager (for example, a default manager) for the specified user (cf. login).
  2. Reads the batch file line by line. One line of a batch file can contain more than one command. A command can span more than one line. For readability reasons it is recommended to code one command per line.
  3. The CLI reads the file until it identifies the next CLI command or reaches the end of the file. This information read (without the possible command identified at the end) is interpreted as a CLI command with its parameter settings and it is executed.

After execution, the scan for the next command or end of file is continued and the scanned command is executed too. This continues until an error occurs or the end of file is reached. The following example provides the contents of a batch file.

regsw -item=prod_1 -version=1.0 -path=/products/prod_1 ~procedures=/products/proc_1
regsw -item=prod_2 -version=1.1 -path=/products/prod_2 ~procedures=/products/proc_2

This batch file registers two products at the SD. The CLI first scans the file until it finds the second regsw and then processes the regsw command for prod_1 with the parameters item, version, path, and procedures. If this succeeds, it scans the rest of the file till end of file and processes the second regsw too. If the first regsw fails, then the second regsw is not executed and the CLI terminates.

For documentation purposes it is possible to add comments to a batch file. Comments are indicated by the hash sign “#”. Whatever follows a hash sign until the end of a line is treated by the CLI as a comment and is ignored. Due to the special meaning of the “#,” avoid it in parameter settings. If a parameter contains a hash sign, enclose the parameter value in quotes to prevent the CLI from interpreting the sign as a comment start. The contents of the file above could therefore turn into the following:

# Register product 1 
regsw -item=prod_1 -version=1.0 -path=/products/prod_1 ~procedures=/products/proc_1 -comment=”product_1 for department #1”
# Register product 2
regsw -item=prod_2 -version=1.1 -path=/products/prod_2 ~procedures=/products/proc_2 -comment=”product_2 for department #100”

By the way not only parameter values containing “#” should be enclosed in quotes but also values containing blanks.

The parameters in the examples are preceded by a hyphen. “stagingServer” is such a parameter that also exists as a CLI command.

The CLI normally terminates the batch processing when the execution of a command fails. But sometimes the commands of a batch file are independent of each other. As in the previous example, the products prod_1 and prod_2 might be independent. So if the registration of prod_1 fails, this will have no impact on the registration of prod_2 and therefore the product prod_2 could be registered. By setting the environment variable:

set SDCMD_CONTINUE=ON (Windows)
export SDCMD_CONTINUE=ON (Linux, bash)

The CLI can be forced to ignore failures and to continue processing with the next command from the file. If these variables are set, the CLI tries to register prod_2 even if the registration of prod_1 fails.

The CLI records the commands processed and the output provided by the commands on stdout. This output can easily be redirected into a file for further analysis by another script. For example:

002 regsw “item=prod_1” “version=1.0” “path=/products/prod_1” “procedures=/products/proc_1” “comment=product_1 for department #1”
Command is processed …
SDCMD<A000000>: OK

004 regsw “item=prod_2” “version=1.1” “path=/products/prod_2” “procedures=/products/proc_2” “comment=product_2 for department #100”
Command is processed …
SDCMD<A000000>: OK

The CLI records the commands read and the parameter settings. The figure in front of the command refers to the line in the batch file where the command has been detected.

All valid commands of the CLI are available at the batch interface.