JBoss.orgCommunity Documentation

Chapter 3. Working with Scripts

3.1. How to write your own scripts
3.2. Executing script file in interactive mode
3.3. Executing script file in non-interactive mode
3.4. Log File and Recorded Script file

Open up a text editor, and enter all the commands in a editor and save the file “.bsh” extension and place it in the distribution where MMAdmin tool can access it. Take  a look at the “samples” directory for example scripts. For example:

// foo.bsh

execute("select * from pm1.g1");

and execute this script file using instructions in Executing script file in non-interactive mode section.

All script files that need to be executed in the non-interactive mode must have the following two lines at the beginning of the script file before execution. These two commands will load all the necessary libraries into the shell before execution.


To execute a script file "foo.bsh" in a directory "some/directory" in interactive mode, execute as following

mmadmin $ source ("some/directory/foo.bsh");

"foo.bsh" is read into current context of the shell as if you typed in the whole document. If your script only contained method calls, you can explicitly invoke the call to execute.

To execute a script file "foo.bsh" in a directory "some/directory" in non-interactive mode, execute as following command at the command prompt

mmadmin.sh some/directory/foo.bsh

Note that, in the script mode it is NOT possible to pass in the command line parameters as

mmadmin.sh some/directory/foo.bsh One Two

The parameters can be passed in as Java system properties. For example

mmadmin.sh some/directory/foo.bsh input1=One input2=Two

Inside the script file, you can access these properties using Java system property semantics

value = System.getProperty(“input1”); // will return "One"

During the interactive mode, all the commands executed by the user are recorded in "adminscript.txt" file.  This file can be found in the root installation directory. This file later can serve as reference to commands that are executed or  will aid in converting commands executed in the interactive mode into a standalone script, that can be run at a later time.

User can also capture the commands entered during a interactive session to their own script file by using “startRecording” and “stopRecording” commands. For example,

mmadmin $ startRecording (“directory/filename.bsh”);
mmadmin $ <commands..>
mmadmin $ stopRecording()    

in this case all the commands executed after the “startRecording” and before the “stopRecording” are captured in the “directory/filename.bsh” file. This gives the user an option to capture only certain portions of the interactive session tat they are interested in and ignore the rest of it.

Also note that all the output during the interactive mode is sent to "mmadmin.log" file. In the script mode, no such files are created.  In script mode, user can capture the standard out and redirect to a file if they need the log file.