Friday 25 October 2019

Creating Alias for JBOSS CLI command in Linux env..

In this tutorial I'll share  creating alias for your JBOSS CLI command in Linux env.. 

Normally you can connect to a running standalone server or managed domain by using the connect command as below.

/jboss/jboss-eap-6.4/bin/jboss-cli.sh --connect --controller=127.0.0.1:9999  --user=admin --password=password 

In JBOSS environment, often need to use JBOSS CLI commands repeatedly. Typing or copying the same command again and again reduces your productivity and distracts you from what you are doing.

You can save yourself some time by creating alias for your JBOSS CLI command.  Alias is like a shortcut command which will have same functionality as if we are writing the whole command.

First, I am creating CLI properties file as below, where Host, Port, User and Password are present.

[jboss@middleware jboss]$ cat cli.props 
host="127.0.0.1"
port=9999
user="jbossas"
password="jboss@456"
[jboss@middleware jboss]$ 

Next, I am adding below line into ~/.bash_profile and Save the same file.  

alias cli='_(){  (. /jboss/jboss-eap-6.4/cli.props ;  /jboss/jboss-eap-6.4/bin/jboss-cli.sh --controller=$host:$port --connect --user=$user --password=$password ; ) }; _'

The file will be automatically loaded in your next session. If you want to use the newly defined alias in the current session, issue the following command:

[jboss@middleware jboss]$ source ~/.bash_profile
[jboss@middleware jboss]$

Test our alias command (cli) whether it's working or not. 

[jboss@middleware jboss]$ cli
[domain@127.0.0.1:9999 /]

It's  working successfully....