WildFly ships with a powerful Command Line Interface which can be run interactively or not. In this tutorial we will learn how to run CLI commands in non-interactive mode.
Running CLI commands in a File
The simplest option to run CLI commands in non-interactive mode is to include the commands in a text file and execute them as follows:
./jboss-cli -c --file=script.cli
In the above example, we have also included the -c (alias for –connect) to connect automatically to the default server address before running the commands.
Running CLI commands from the prompt
Another option is to include the CLI commands directly in the shell.
$JBOSS_HOME/bin/jboss-cli.sh -c "/subsystem=logging/logger=*:read-resource"
If you need to provide Username/Password on the command line, you can use the following options:
$JBOSS_HOME/bin/jboss-cli.sh -c controller=$JBOSS_IP:9990 --user=$USER --password=$property_value --command="/subsystem=logging:read-resource"
If you need to execute multiple CLI commands in the same sessions then you can use the –commands option, which includes a comma, separated list of commands. For example:
./jboss-cli.sh --commands="connect,deploy example.war"
How to echo CLI Commands in non-interactive mode
When you are running large CLI scripts it is a good idea to echo the commands, especially when you are testing the scripts. In order to enable echoing of single CLI commands in a script, add the option –echo-command. For example:
$JBOSS_HOME/bin/jboss-cli.sh --file=test.cli --echo-command
Then, you will be able to see the single CLI commands and the result in the Console