Posts Tagged ‘bash’

Medindo consecutivos tempos de subida do JBoss

December 5th, 2011

Estava com um problema que causava congelamentos de até 10 minutos nas máquinas do JBoss em um cliente. Estes congelamentos eram intermitentes e aconteciam sempre no boot do JBoss.

A fim de fazer testes com várias configurações diferentes e gerar um relatório com dados precisos, escrevi um script que executa o init script do JBoss, espera ele inicializar completamente, grava o tempo de inicialização e mata o processo. Faz isso 50 vezes.

Estou postando ele aqui na esperança de ser útil para mais alguém. Ele é bastante auto-explicativo:

#!/bin/bash
# Notes: all Java processes are going to the KILLED and
# previous probe.log ERASED!
 
JBOSS_LOG_FILE="/opt/jboss/server/default/log/server.log"
REPEAT=50
 
START_STRING="Started in"
RESULT_FILE="/root/probe.log-`date +%F`"
> $RESULT_FILE
 
for i in $(seq 1 $REPEAT); do
	# clean
	killall -9 java
	> $JBOSS_LOG_FILE
 
	# init and wait
	sh /etc/init.d/jboss start
	while [ "x$( grep "$START_STRING" $JBOSS_LOG_FILE )" == "x" ]; do
		sleep 1
	done
 
	# log
	cat $JBOSS_LOG_FILE | grep "$START_STRING" >> $RESULT_FILE
done
 
echo "Done"

Quick one

May 26th, 2008

This one is for all of you who (like me) keeps wasting time using commands such as find, jar and grep each time you get a classpath error:

#!/bin/bash
if [ "$1" = "" ]; then
	echo "Usage: jarfind REGEXP";
	exit;
fi
 
for d in `find . -name '*.jar'` ; do
	FILES=`unzip -l $d | cut -c 29- | egrep ''$1''`;
 
	if [ "$FILES" != "" ]; then
		echo "$d";
 
		for f in $FILES ; do
			echo " - $f"
		done
	fi
done

I’ve chose to use unzip instead of jar since it’s far more commonly seem. Move it to /usr/local/bin/jarfind (well, that’s a little personal) and chmod it to +x.

I works searching all jars under the current directory for a regular expression, most commonly a simple class name. It returns the jar’s names and all corresponding class matches.

I’m not a bash programmer, so it may not look that pretty to experienced bash programmers, but it looks beautiful to me, as it saves me a lot of time =). Feel free to make any comments.

EDIT:

first known bug: doesn’t escape special characters in paths =/