Download Red Hat JBoss Operations Network 3.3 Writing JBoss ON Command

Transcript
Red Hat JBoss O perat ions Net work 3.3 Writ ing JBoss O N Command- Line Script s
A single command can be passed to the CLI by using the -c. In this example, the server
searches for and prints all supported resource types for the server and prints the results
to reso urce_types. txt
​r hq-cli.sh -u rhqadmin -p rhqadmin -c
"pretty.print(ResourceTypeManager.findResourceTypesByCriteria(new
ResourceTypeCriteria()))" > resource_types.txt
The R eso urceT ypeManag er. fi nd R eso urceT ypesByC ri teri a(new
R eso urceT ypeC ri teri a()) class invokes the fi nd R eso urceT ypesByC ri teri a
operation on R eso urceT ypeManag er. A new R eso urceT ypeC ri teri a object is
passed as the argument.
Nothing has been specified on the criteria object so all resource types will be returned.
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.
This single command provides a nicely formatted, text-based report of the resource types
in the inventory.
Examp le 10.10. R u n n in g a Scrip t
This executes the script file, my_scri pt. 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
Examp le 10.11. H an d lin g Scrip t Arg u men t s
A feature common to most programming languages is the ability to pass arguments to the
program to be executed. In Java, the entry point into a program is a class's main method,
and it takes a String array as an argument. That array holds any arguments passed to
the program. Similarly, arguments can be passed to CLI scripts. Arguments passed to a
script can be accessed in the implicit args array:
​i f (args.length < 2) {
​
throw "Not enough arguments!";
​
}
​
​
​
​
60
fo r (i i n args) {
println('args[' + i + '] = ' + args[i]);
}