CLI non-interactive mode

Version 7

    Normally, jboss-admin.sh (or jboss-admin.bat) launches a command line session in an interactive mode, meaning it is prompting the user to type in commands and operations and prints the results of the performed actions in the same terminal window for the user to see. There is also another (non-interactive) mode to execute commands and operations that doesn't require typing them after the prompt. The commands can be stored in a file which can be specified as an argument to jboss-admin.sh (or jboss-admin.bat) or even the commands themselves can be specified as arguments to jboss-admin.sh (or jboss-admin.bat). In this case, the CLI session will not display the prompt but just execute the commands and operations listed in the file or specified as the arguments to jboss-admin.sh (or jboss-admin.bat) and quit after the last command has been executed.

     

    In order to match a command with its output, you can provide the option --echo-command (or add the XML element <echo-command> to the CLI configuration file) in order to make the CLI to include the prompt + command + options in the output. With this option enabled, any executed command will be added to the output.

     

    Commands in a file

     

    If there is a sequence of commands and/or operations that need to be executed regularly, they can be stored in a file one command or operation per line and this file can be specified as the input source for the CLI. E.g. suppose we have a file test.cli with the following content:

     

    version

     

    We can execute this file like this

     

    ./jboss-cli.sh --file=test.cli

    JBoss Admin Command-line Interface

    JBOSS_HOME: /home/XXX/git/jboss-as/build/target/jboss-as-7.1.0.Alpha1-SNAPSHOT

    JAVA_HOME: /opt/jdk/

    java.version: 1.6.0_21

    java.vm.vendor: Sun Microsystems Inc.

    java.vm.version: 17.0-b16

    os.name: Linux

    os.version: 2.6.35.13-92.fc14.i686.PAE

     

     

    The CLI session is terminated after all the commands and operations have been executed. Note, the CLI doesn't automatically connects to the controller. So, if you want to execute a command or an operation which requires a connection to the controller, you can either add connect command to the file, e.g.

     

    connect

    ls


    ./jboss-cli.sh --file=test.cli

    Connected to standalone controller at localhost:9999

    extension

    core-service

    path

    subsystem

    system-property

    deployment

    interface

    socket-binding-group

    Closed connection to localhost:9999

     

    The connection to the controller will be closed implicitly before the CLI session terminates.

     

    Or instead of adding the command to the file, you could add --connect (or its shorter version -c) argument to jboss-admin.sh (or jboss-admin.bat), e.g.

     

    ls

     

    ./jboss-cli.sh -c --file=test.cli

    Connected to standalone controller at localhost:9999

    extension

    core-service

    path

    subsystem

    system-property

    deployment

    interface

    socket-binding-group

     

    Commands as arguments

     

    If all you want to do is execute a single command, then you can specify it using --command argument, e.g.

     

    ./jboss-cli.sh -c --command=ls

    Connected to standalone controller at localhost:9999

    extension

    core-service

    path

    subsystem

    system-property

    deployment

    interface

    socket-binding-group

     

    or just

     

    ./jboss-cli.sh -c ls

    Connected to standalone controller at localhost:9999

    extension

    core-service

    path

    subsystem

    system-property

    deployment

    interface

    socket-binding-group

     

    If you want to execute more than one command then you should use -commands argument and separate commands with commas, e.g.

     

    ./jboss-cli.sh -c --commands="cd subsystem=web,ls"

    Connected to standalone controller at localhost:9999

    virtual-server

    connector

     

    Note,  the quotes are necessary in this case because between cd and its argument there is a space.

    Or a shorter version of the above

     

    ./jboss-cli.sh -c "cd subsystem=web,ls"

    Connected to standalone controller at localhost:9999

    virtual-server

    connector