Specifying the “batch” keyword the batch interface of the CLI is invoked. 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. It first establishes a session to the specified manager (for example, a default manager) for the specified user (cf. login). Then it reads the batch file line by line. One line of a batch file can contain more than one command, on the other hand a command can span more than one line. For readability reasons it is recommended to code one command per line. The CLI reads the file from the start until it identifies the next CLI command or it reaches the end of file, what ever comes first. 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 a success full 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 presents a 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 will not be 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 “#”. What ever follows a hash sign until the end of a line is understood by the CLI as a comment and is ignored. Due to the special meaning of the “#” it should be avoided in parameter settings. Nevertheless it might happen that a parameter contains a hash sign. In this case 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 above are preceded by a hyphen “-“. It is recommended to indicate parameters in such a way although it is not a must. Nevertheless in case of ambiguous parameters that could be mistaken for a command the hyphen should be set. “stagingServer” is such a parameter that also exists as a CLI command.
As stated above the CLI will normally terminate 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 example above 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. As an example the
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 as it is understood by the CLI. 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.
|
Copyright © 2013 CA.
All rights reserved.
|
|