<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rafael Liu Blog &#187; bash</title>
	<atom:link href="http://rafaelliu.net/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://rafaelliu.net</link>
	<description>Café, pinguins e outras coisas</description>
	<lastBuildDate>Wed, 28 Mar 2012 21:54:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Medindo consecutivos tempos de subida do JBoss</title>
		<link>http://rafaelliu.net/2011/12/05/medindo-consecutivos-tempos-de-subida-do-jboss/</link>
		<comments>http://rafaelliu.net/2011/12/05/medindo-consecutivos-tempos-de-subida-do-jboss/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 19:01:26 +0000</pubDate>
		<dc:creator>rafaelliu</dc:creator>
				<category><![CDATA[Diverso]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://rafaelliu.net/?p=585</guid>
		<description><![CDATA[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, [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>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.</p>
<p>Estou postando ele aqui na esperança de ser útil para mais alguém. Ele é bastante auto-explicativo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># Notes: all Java processes are going to the KILLED and</span>
<span style="color: #666666; font-style: italic;"># previous probe.log ERASED!</span>
&nbsp;
<span style="color: #007800;">JBOSS_LOG_FILE</span>=<span style="color: #ff0000;">&quot;/opt/jboss/server/default/log/server.log&quot;</span>
<span style="color: #007800;">REPEAT</span>=<span style="color: #000000;">50</span>
&nbsp;
<span style="color: #007800;">START_STRING</span>=<span style="color: #ff0000;">&quot;Started in&quot;</span>
<span style="color: #007800;">RESULT_FILE</span>=<span style="color: #ff0000;">&quot;/root/probe.log-<span style="color: #780078;">`date +%F`</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$RESULT_FILE</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">seq</span> <span style="color: #000000;">1</span> <span style="color: #007800;">$REPEAT</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #666666; font-style: italic;"># clean</span>
	<span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-9</span> java
	<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$JBOSS_LOG_FILE</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># init and wait</span>
	<span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>jboss start
	<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;x<span style="color: #007800;">$( grep &quot;$START_STRING&quot; $JBOSS_LOG_FILE )</span>&quot;</span> == <span style="color: #ff0000;">&quot;x&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># log</span>
	<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$JBOSS_LOG_FILE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$START_STRING</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$RESULT_FILE</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Done&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rafaelliu.net/2011/12/05/medindo-consecutivos-tempos-de-subida-do-jboss/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Quick one</title>
		<link>http://rafaelliu.net/2008/05/26/quick-one/</link>
		<comments>http://rafaelliu.net/2008/05/26/quick-one/#comments</comments>
		<pubDate>Mon, 26 May 2008 19:03:28 +0000</pubDate>
		<dc:creator>rafaelliu</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://rafaelliu.wordpress.com/?p=12</guid>
		<description><![CDATA[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 &#91; &#34;$1&#34; = &#34;&#34; &#93;; then echo &#34;Usage: jarfind REGEXP&#34;; exit; fi &#160; for d in `find . -name '*.jar'` ; do FILES=`unzip -l $d [...]]]></description>
			<content:encoded><![CDATA[<p>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:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> = <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: jarfind REGEXP&quot;</span>;
	<span style="color: #7a0874; font-weight: bold;">exit</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> d <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.jar'</span><span style="color: #000000; font-weight: bold;">`</span> ; <span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #007800;">FILES</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">unzip</span> <span style="color: #660033;">-l</span> <span style="color: #007800;">$d</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">29</span>- <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #ff0000;">''</span><span style="color: #007800;">$1</span><span style="color: #ff0000;">''</span><span style="color: #000000; font-weight: bold;">`</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FILES</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$d</span>&quot;</span>;
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$FILES</span> ; <span style="color: #000000; font-weight: bold;">do</span>
			<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; - <span style="color: #007800;">$f</span>&quot;</span>
		<span style="color: #000000; font-weight: bold;">done</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>I&#8217;ve chose to use unzip instead of jar since it&#8217;s far more commonly seem. Move it to /usr/local/bin/jarfind  (well, that&#8217;s a little personal) and chmod it to +x.</p>
<p>I works searching all jars under the current directory for a regular expression, most commonly a simple class name. It returns the jar&#8217;s names and all corresponding class matches.</p>
<p>I&#8217;m <span style="text-decoration:underline;">not</span> 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.</p>
<p><strong>EDIT:</strong></p>
<p>first known bug: doesn&#8217;t escape special characters in paths =/</p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelliu.net/2008/05/26/quick-one/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

