Questo contenuto non è disponibile nella lingua selezionata.
10.3. Passing Command and Script Arguments
rhq-cli.sh
, commands or full scripts can be passed simultaneously. This is a non-interactive way to connect to the CLI, since the CLI runs the specified command or script and then exits, rather than staying connected in interactive mode.
Example 10.9. Passing Variables to the Server
-c
. In this example, the server searches for and prints all supported resource types for the server and prints the results to resource_types.txt
rhq-cli.sh -u rhqadmin -p rhqadmin -c "pretty.print(ResourceTypeManager.findResourceTypesByCriteria(new ResourceTypeCriteria()))" > resource_types.txt
rhq-cli.sh -u rhqadmin -p rhqadmin -c "pretty.print(ResourceTypeManager.findResourceTypesByCriteria(new ResourceTypeCriteria()))" > resource_types.txt
ResourceTypeManager.findResourceTypesByCriteria(new ResourceTypeCriteria())
class invokes the findResourceTypesByCriteria
operation on ResourceTypeManager
. A new ResourceTypeCriteria
object is passed as the argument.
pretty
is an implicit object made available to commands and scripts by the CLI. This is useful for outputting objects in a readable, tabular format which is designed for domain objects.
Example 10.10. Running a Script
my_script.js
. The CLI terminates immediately after the script has finished executing.
cliRoot/rhq-remoting-cli-4.9.0.JON320GA/bin/rhq-cli.sh -f /export/myScripts/my_script.js
cliRoot/rhq-remoting-cli-4.9.0.JON320GA/bin/rhq-cli.sh -f /export/myScripts/my_script.js
Example 10.11. Handling Script Arguments
cliRoot/rhq-remoting-cli-4.9.0.JON320GA/samples/modules
directory.
cliRoot/rhq-remoting-cli-4.9.0.JON320GA/bin/rhq-cli.sh -s jon-server.example.com -u rhqadmin -p rhqadmin -t 7080 echo_args.js --args-style=named x=1 y=2
[jsmith@server ~]$ cliRoot/rhq-remoting-cli-4.9.0.JON320GA/bin/rhq-cli.sh -s jon-server.example.com -u rhqadmin -p rhqadmin -t 7080 echo_args.js --args-style=named x=1 y=2
echo_args.js
, for example, is written to accept the two named option with the script invocation, x and y.
- Explicitly specify that you are using named arguments with the --args-style option.
- The values of the named arguments are still accessible through the implicit args array.
- The named arguments, such as x and y, are bound into the script context as variables.
Example 10.12. Executing a Single Statement
-c
option with rhq-cli.sh
.
localhost:7080> var x = 1
localhost:7080> var x = 1
Example 10.13. Executing a Multi-Line Statement
Example 10.14. Executing a Script
-f
option with the rhq-cli.sh|bat script.
-f
option must give the absolute location of the script, even if it is in the same directory as the rhq-cli.sh
script. The CLI will not find a script with only a relative path.
cliRoot/rhq-remoting-cli-4.9.0.JON320GA/bin/rhq-cli.sh -u rhqadmin -p rhqadmin -s jon-server.example.com -t 7080 -f /absolute/path/to/myscript.js
[jsmith@server ~]$ cliRoot/rhq-remoting-cli-4.9.0.JON320GA/bin/rhq-cli.sh -u rhqadmin -p rhqadmin -s jon-server.example.com -t 7080 -f /absolute/path/to/myscript.js
Example 10.15. Executing a Script with Arguments
cliRoot/rhq-remoting-cli-4.9.0.JON320GA/bin/rhq-cli.sh -u rhqadmin -p rhqadmin -s jon-server.example.com -t 7080 -f /absolute/path/to/myscript.js 1 2 3
[jsmith@server ~]$ cliRoot/rhq-remoting-cli-4.9.0.JON320GA/bin/rhq-cli.sh -u rhqadmin -p rhqadmin -s jon-server.example.com -t 7080 -f /absolute/path/to/myscript.js 1 2 3
Example 10.16. Executing a Script with Named Arguments
cliRoot/rhq-remoting-cli-4.9.0.JON320GA/bin/rhq-cli.sh -u rhqadmin -p rhqadmin -s jon-server.example.com -t 7080 --args-style=named -f /absolute/path/to/myscript.js x=1 y=2 y=3
[jsmith@server ~]$ cliRoot/rhq-remoting-cli-4.9.0.JON320GA/bin/rhq-cli.sh -u rhqadmin -p rhqadmin -s jon-server.example.com -t 7080 --args-style=named -f /absolute/path/to/myscript.js x=1 y=2 y=3