<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    CLI Batch Mode
</h3>
<span style="margin-bottom: 10px;">
    modified by <a href="https://community.jboss.org/people/aloubyansky">Alexey Loubyansky</a> in <i>JBoss AS 7 Development</i> - <a href="https://community.jboss.org/docs/DOC-16728">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>The batch mode allows one to group commands and operations and execute them together as an atomic unit, i.e., if at least one of the commands or operations fails, all the other successfully executed commands and operations in the batch are rolled back.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Not all of the commands can be added to a batch. E.g. commands like 'cd', 'ls', 'help', etc are not added to the batch since they don't translate into operation requests. These commands (if entered while in the batch mode) will be executed outside of the batch. Only the commands that translate into operation requests are allowed in the batch. The batch, actually, translates into a 'composite' operation request.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h2>Composing batches from scratch</h2><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Interactive mode begins with the <em>batch</em> command.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 /] batch
[standalone@localhost:9999 / #]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The '#' sign in the prompt indicates that the CLI is in the batch mode. Operations and commands like deploy, data-source, etc won't be executed as they are entered, instead they will be added to the current batch.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 / #] deploy my.ear
#1 deploy my.ear
[standalone@localhost:9999 / #] data-source enable --name=ExampleDS
#2 data-source enable --name=ExampleDS
[standalone@localhost:9999 / #] /system-property=myprop:add(value=myvalue)
#3 /system-property=myprop:add(value=myvalue)
[standalone@localhost:9999 / #]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> But commands that don't translate into operation requests (or commands that are read-only) will be executed immediately, i.e. outside the batch. E.g.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 / #] ls
extension&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; path&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; subsystem&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; deployment&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; management-interfaces
interface&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; socket-binding-group
[standalone@localhost:9999 / #] cd subsystem=web
[standalone@localhost:9999 subsystem=web #] read-attribute default-virtual-server
default-host
[standalone@localhost:9999 subsystem=web #]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>To see the list of the commands and operations in the current batch execute <em>list-batch</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 / #] list-batch 
#1 deploy my.ear
#2 data-source enable --name=ExampleDS
#3 /system-property=myprop:add(value=myvalue)
[standalone@localhost:9999 / #]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Any line in the batch can be edited with <em>edit-batch-line</em> command by providing the line number as the first argument and the edited command as the second one</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 / #] edit-batch-line 2 data-source disable --name=ExampleDS
#2 data-source disable --name=ExampleDS
[standalone@localhost:9999 / #]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>If you want to re-order the lines in the batch you can do this using <em>move-batch-line</em> by specifying the line number you want to move as the first argument and its new position as the second argument</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 / #] move-batch-line 3 1
[standalone@localhost:9999 / #] list-batch 
#1 /system-property=myprop:add(value=myvalue)
#2 deploy my.ear
#3 data-source disable --name=ExampleDS
[standalone@localhost:9999 / #]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>A line can be removed using <em>remove-batch-line</em> specifying the line number as the argument</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 / #] remove-batch-line 2
[standalone@localhost:9999 / #] list-batch 
#1 /system-property=myprop:add(value=myvalue)
#2 data-source disable --name=ExampleDS
[standalone@localhost:9999 / #]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>You can postpone batch editing if suddenly you want to perform some other tasks outside the batch by executing <em>holdback-batch</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 / #] holdback-batch 
[standalone@localhost:9999 /]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>To return to the held back batch, just execute <em>batch</em> command</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 /] batch 
Re-activated batch
#1 /system-property=myprop:add(value=myvalue)
#2 data-source disable --name=ExampleDS
[standalone@localhost:9999 / #]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Actually, it's possible to hold back more than one batch by specifying the name under which the batch should be saved (in runtime memory)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 / #] holdback-batch mybatch
[standalone@localhost:9999 /]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Now, the batch is saved under the name 'mybatch'. To activate it, you now have to execute <em>batch mybatch</em>. Executing <em>batch</em> without arguments will start a new batch.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 /] batch
[standalone@localhost:9999 / #] deploy my.ear
#1 deploy my.ear
[standalone@localhost:9999 / #] holdback-batch 
[standalone@localhost:9999 /]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Now there are two batches held back. Too see the list of all the held back batches, execute <em>batch</em> with <em>-l</em> switch</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 /] batch -l
&lt;unnamed&gt;
mybatch
[standalone@localhost:9999 /]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The unnamed batch (there can be only one unnamed batch) is activated by executing <em>batch</em> without arguments</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 /] batch 
Re-activated batch
#1 deploy my.ear
[standalone@localhost:9999 / #]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The currently active batch can be discarded by executing <em>discard-batch</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 / #] discard-batch 
[standalone@localhost:9999 /] batch -l
mybatch
[standalone@localhost:9999 /]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Note, that after you re-activate your batch it is removed from the held back list and not associated with any name anymore. So, if you want to hold it back again, you will have to give it a new unique name or leave it unnamed.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Finally, to execute the currently active batch use <em>run-batch</em> command. A successfully executed batch is automatically discarded and the CLI leaves the batch mode.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 /] batch mybatch
Re-activated batch 'mybatch'
#1 /system-property=myprop:add(value=myvalue)
#2 data-source disable --name=ExampleDS
[standalone@localhost:9999 / #] run-batch 
The batch executed successfully
[standalone@localhost:9999 /] batch -l
[standalone@localhost:9999 /]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h2></h2><h2>Executing batches stored in files</h2><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>In case there is a set of commands and operations that peform a common task which could be executed frequently, they could be saved in a file which later could be specified as the argument to the <em>batch</em> command. In this case the <em>batch</em> command will start the batch mode and load the commands and operations from the specified file into the current batch. Now, you can edit the batch (edit, remove, add lines) and/or simply execute <em>run-batch</em>.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 /] batch --file=myscript.txt
[standalone@localhost:9999 / #] list-batch 
#1 deploy my.ear
#2 data-source --name=ExampleDS --min-pool-size=5
[standalone@localhost:9999 / #] data-source --name=ExampleDS --max-pool-size=10
#3 data-source --name=ExampleDS --max-pool-size=10
[standalone@localhost:9999 / #] run-batch 
The batch executed successfully
[standalone@localhost:9999 /]</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>In case you don't need to modify the batch stored in the file, you can simply execute it by passing the file name as the argument to <em>run-batch</em> without previously loading it using <em>batch.</em></p><p><pre class="jive-pre"><code class="jive-code">[standalone@localhost:9999 /] run-batch --file=myscript.txt
The batch executed successfully
[standalone@localhost:9999 /]</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h2>Headers for batch request</h2><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>run-batch</em> command accepts <em>--headers</em> argument which can be used to attach operation headers to the composite operation request the batch translates to. Please, refer to the paragraph <strong>Headers</strong> on <a class="" href="https://community.jboss.org/docs/DOC-17599">The operation request format article</a> to find out more about the supported headers and their syntax.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h2>Batches with properties</h2><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>In case you need to parameterize your batches, you could use system properties. This is described in <a class="jive-link-wiki-small" href="https://community.jboss.org/docs/DOC-18726">System properties in command argument and operation parameter values</a>.</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="https://community.jboss.org/docs/DOC-16728">going to Community</a></p>

        <p style="margin: 0;">Create a new document in JBoss AS 7 Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2225">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>