## Just general enough

When I write a utility — a shell script, batch file, Python script… — I’m always trying to write it so that a co-worker could receive a copy of the script and not have to do rework in order to use it.

Yesterday, though, I followed this procedure for the Nth time:

1. Shut down JBoss
2. Open up folder F; Select sample-project(T-transaction-manager).war; Copy
3. Open up JBoss server/default/deploy folder;Delete sample-project.war
4. Paste sample-project(T-transaction-manager).war; rename to sample-project.war
5. Restart JBoss

(T can be hibernate or jta)

Having the two different .wars pre-built and able to just be copied to the deploy directory was already an optimization of my procedure; before that I had been toggling the transaction manager and rebuilding the project each time I needed to redeploy!

As I went, though, I found myself wanting to get a little information from the one kind of deployment, then quickly switch to the other and try the same thing to compare results.  It was time for something more streamlined, something that didn’t break my flow so much.  Here’s what I came up with.

## txdeploy.cmd

I renamed the two .wars to sample-project(hib).war and sample-project(jta).war and wrote a supporting batch file named txdeploy.cmd:

@echo off
if not %1==jta if not %1==hib if not %1==which echo Usage: txdeploy jta (or) txdeploy hib (or) txdeploy which && goto End

if not %1==which goto deploy

:which
for %%f in (jta hib) do fc "C:\path\to\sample-project(%%f).war" C:\path\to\jboss-4.2.2.GA\server\default\deploy\sample-project.war > NUL && echo %%f version is deployed
goto End

:deploy
copy /y "C:\path\to\sample-project(%1).war" C:\path\to\jboss-4.2.2.GA\server\default\deploy\sample-project.war
goto which

:End


Now I can run txdeploy hib from the Windows command prompt to deploy the version that uses a Hibernate transaction manager, and txdeploy jta to deploy the JTA one instead.  I can also run txdeploy which, which displays hib version is deployed or jta version is deployed, as appropriate.

Now my workflow is:

1. Shut down JBoss
2. type txdeploy hib (for example) at the Windows command prompt
3. Restart JBoss

Much nicer!

1. #1 by Ben Dean on December 2, 2008 - 9:18 am

You have cygwin on your system and you chose to do this using an MS-DOS batch script? Use a the real man’s shell, bash!! Way better for this kind of thing (actually it’s more of a preference but I think it’s better)

:)

2. #2 by danielmeyer on December 2, 2008 - 11:27 am

Funny, I generally write batch files by default, not because I like them better but because my hotkeys always take me to a Windows command prompt. If my hotkeys took me to a Cygwin bash prompt, maybe it would feel more natural to write bash scripts by default!

Update: Try this!

#!/bin/bash

if [ "$1" != "jta" -a "$1" != "hib" -a "$1" != "which" ]; then echo Usage: echo " txdeploy jta" echo " txdeploy hib" echo " txdeploy which" exit fi PATH_TO_WARS=${USERPROFILE}/common-dirs
JBOSS_DEPLOY_DIR=/cygdrive/c/installs/jboss-4.2.2.GA/server/default/deploy

if [ "$1" != "which" ]; then cp "$PATH_TO_WARS/sample-project($1).war"$JBOSS_DEPLOY_DIR/sample-project.war
fi

for f in jta hib; do
diff "${PATH_TO_WARS}/sample-project($f).war" $JBOSS_DEPLOY_DIR/sample-project.war > /dev/null && echo$f version is deployed
done

3. #3 by Henryk Konsek on December 3, 2008 - 2:53 am

Hi

Talking about shells – try zsh. The most people using it feel illuminated :) We used to say that distance(bat,bash) == distance(bash,zsh). However I don’t know if you can use zsh under Cygwin.

Kind regards.

4. #4 by danielmeyer on December 3, 2008 - 8:25 am

Henryk,

Thanks for the comment! Could you help me understand what you like so much better about zsh? (I have some inertia toward staying with bash, but I’d like to know what I’m missing… :)

5. #5 by Henryk Konsek on December 4, 2008 - 3:10 am

Hi

First of all – tab complation. Far more advanced than advanced one from the bash :) You can even complete files in archives when using tar or complete file names from the REMOTE filesystem (using ssh + PKI).

Another interesing feature is intelligent shell spellChecker. For example ‘cat /etc/fstsb’ could result in ‘Did you mean: cat /etc/fstab’ .

Prompt in zsh can be easily configured to look MUCH nicer than these in bash. You can choose even predefined themes :)

You can create advanced global aliases like:
% cat /etc/fstab g foo
…for…
% cat /etc/fstab | grep foo
…or…
% cat /etc/fstab L
…for…
% cat /etc/fstab | less

Also history search is much more sophisticated than in bash :) Really cool :)

Some additional simplified if/for statements are also available (these old from bash suck).

Oh, and advanced globbing :] For example:
% myMp3Player ~/mp3/**/*.mp3
…for recursive patterns (including subdirectories) :)

And these things above are just a top of the iceberg. :) In general zsh is modular – you can enable selected features. By default zsh is very similar to the bash :) Then you choose what you want to enhance (for example themes + suggestions + globbing).

Kind regards.