<?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>Another Geek Blog &#187; bash</title>
	<atom:link href="http://geek.linuxman.pro.br/tag/bash/feed" rel="self" type="application/rss+xml" />
	<link>http://geek.linuxman.pro.br</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 16 Dec 2011 01:55:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Criando DNS dinâmicos com sua conta no DreamHost</title>
		<link>http://geek.linuxman.pro.br/geek/criando-dns-dinamicos-com-sua-conta-no-dreamhost</link>
		<comments>http://geek.linuxman.pro.br/geek/criando-dns-dinamicos-com-sua-conta-no-dreamhost#comments</comments>
		<pubDate>Fri, 08 Oct 2010 11:30:57 +0000</pubDate>
		<dc:creator>Eri</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://geek.linuxman.pro.br/?p=1454</guid>
		<description><![CDATA[Sou cliente do DreamHost já faz um tempo e acho o serviço deles sensacional. Uma feature que eu ainda não tinha usado é a API que eles disponibilizam para todos os clientes. Bem bacana e flexível. Como em casa eu tenho IP dinâmico e vez por outra ele muda justamente quando preciso acessar de volta [...]]]></description>
			<content:encoded><![CDATA[<p>Sou cliente do DreamHost já faz um tempo e acho o serviço deles sensacional.</p>
<p>Uma feature que eu ainda não tinha usado é a API que eles disponibilizam para todos os clientes. Bem bacana e flexível.</p>
<p>Como em casa eu tenho IP dinâmico e vez por outra ele muda justamente quando preciso acessar de volta resolvi aproveitar e fiz um shell script quick&#8217;n dirty pra usar esse recurso bacana.</p>
<p>Sei que existem diversos serviços de DNS dinâmico por ai, mas preferi essa alternativa que pode ser útil pra mais alguém com uma necessidade parecida. <img src='http://geek.linuxman.pro.br/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a href="http://pastebin.com/XTK05EEV">Tá aqui o script</a>.</p>

	Tags: <a href="http://geek.linuxman.pro.br/tag/bash" title="bash" rel="tag">bash</a>, <a href="http://geek.linuxman.pro.br/tag/dreamhost" title="dreamhost" rel="tag">dreamhost</a>, <a href="http://geek.linuxman.pro.br/tag/linux" title="linux" rel="tag">linux</a>, <a href="http://geek.linuxman.pro.br/tag/shell" title="shell" rel="tag">shell</a><br />
]]></content:encoded>
			<wfw:commentRss>http://geek.linuxman.pro.br/geek/criando-dns-dinamicos-com-sua-conta-no-dreamhost/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restingindo acesso com rbash</title>
		<link>http://geek.linuxman.pro.br/geek/restingindo-acesso-com-rbash</link>
		<comments>http://geek.linuxman.pro.br/geek/restingindo-acesso-com-rbash#comments</comments>
		<pubDate>Tue, 22 Dec 2009 14:34:27 +0000</pubDate>
		<dc:creator>Eri</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[rbash]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://geek.linuxman.pro.br/?p=1293</guid>
		<description><![CDATA[Como sysadmins vez por outra a gente precisa dar acesso a clientes, parceiros ou outro tipo de usuário temporário/untrusted aos servidores. Apesar de criar um jail root completo ser a melhor solução muitas vezes é mais trabalho do que o necessário e começa a entrar naquele cenário em que a segurança atrapalha a usabilidade e [...]]]></description>
			<content:encoded><![CDATA[<p>Como sysadmins vez por outra a gente precisa dar acesso a clientes, parceiros ou outro tipo de usuário temporário/untrusted aos servidores. Apesar de criar um jail root completo ser a melhor solução muitas vezes é mais trabalho do que o necessário e começa a entrar naquele cenário em que a segurança atrapalha a usabilidade e os negócios.</p>
<p>Uma forma simples de conseguir uma segurança bacana é utilizar o modo restrito do bash. Com isso habilitado o shell irá desabilitar as seguintes funções:</p>
<ul>
<li>Mudar o diretório (cd)</li>
<li>Mudar o valor das variáveis SHELL, PATH, ENV, or BASH_ENV</li>
<li>Comandos que incluem /</li>
<li>Especificar um arquivo que contenha / como fonte para o comando &#8220;.&#8221;</li>
<li>Usar redirecionamento de output (&gt;, &gt;&gt;, |)</li>
<li>etc (man bash para todas as features)</li>
</ul>
<p>Colocando para rodar:</p>
<p>Crie um link do bash para o rbash e adicione o mesmo em /etc/shells:</p>
<pre>ln -s /bin/bash /bin/rbash
echo /bin/rbash &gt;&gt; /etc/shells</pre>
<p>Depois é só mudar o shell do usuário a ser restringido para usar o rbash:</p>
<pre>usermod -s /bin/rbash username</pre>
<p>Combinando isso com traps (do CTRL+C, por exemplo) você consegue criar um ambiente seguro o suficiente para fornecer serviços e acessos aos seus servidores e ainda assim dormir à noite.</p>
<p>Como diria o SuSE: Have a lot of fun!</p>

	Tags: <a href="http://geek.linuxman.pro.br/tag/bash" title="bash" rel="tag">bash</a>, <a href="http://geek.linuxman.pro.br/tag/geek" title="Geek" rel="tag">Geek</a>, <a href="http://geek.linuxman.pro.br/tag/linux" title="linux" rel="tag">linux</a>, <a href="http://geek.linuxman.pro.br/tag/rbash" title="rbash" rel="tag">rbash</a>, <a href="http://geek.linuxman.pro.br/tag/sysadmin" title="sysadmin" rel="tag">sysadmin</a><br />
]]></content:encoded>
			<wfw:commentRss>http://geek.linuxman.pro.br/geek/restingindo-acesso-com-rbash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Desafio do Beakman</title>
		<link>http://geek.linuxman.pro.br/geek/desafio-do-beakman</link>
		<comments>http://geek.linuxman.pro.br/geek/desafio-do-beakman#comments</comments>
		<pubDate>Tue, 16 Jun 2009 01:43:29 +0000</pubDate>
		<dc:creator>Eri</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://geek.linuxman.pro.br/?p=1123</guid>
		<description><![CDATA[Lembram do Beakman?  uhauhauhauha&#8230; Eu cai na seguinte situação: Tenho um número X de servidores que tem um usuário que eu posso utilizar para dar login. Existem 4 senhas possíveis para este usuário, mas eu não sei qual senha está em qual servidor, de forma que eu tenho que ir tentando até conseguir quando tento [...]]]></description>
			<content:encoded><![CDATA[<p>Lembram do <a href="http://en.wikipedia.org/wiki/Beakman%27s_World">Beakman</a>?  uhauhauhauha&#8230;</p>
<p>Eu cai na seguinte situação: Tenho um número X de servidores que tem um usuário que eu posso utilizar para dar login. Existem 4 senhas possíveis para este usuário, mas eu não sei qual senha está em qual servidor, de forma que eu tenho que ir tentando até conseguir quando tento conectar no mesmo.</p>
<p>Depois de conseguir dar login na máquina eu tenho que virar root. Eu sei que cada servidor tem uma senha de root diferente, mas sempre que eu usar a senha de usuário X a senha de root vai ser Y, senha de usuário A, senha de root B.</p>
<p>Até o momento só consegui semi-automatizar o processo, mostrando na tela qual senha funcionou para o usuário, de forma que eu vou saber qual senha de root usar. O ideal é automatizar o login de forma que eu só precise bater o nome da máquina e já caia no prompt de root.</p>
<p>O que fiz foi:</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>
&nbsp;
<span style="color: #007800;">senhas</span>=<span style="color: #ff0000;">&quot;senha1 senha2 senha3 senha4&quot;</span>
&nbsp;
<span style="color: #007800;">SERVER</span>=<span style="color: #007800;">$1</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> senha <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$senhas</span>
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">SSHPASS</span>=<span style="color: #007800;">$senha</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Tentando <span style="color: #007800;">$senha</span>&quot;</span>
    sshpass <span style="color: #660033;">-e</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> user<span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$SERVER</span>
    <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>O <a href="http://tarzxvf.com/">Pascal</a> me sugeriu o <a href="http://www.lag.net/paramiko/">paramiko</a>, mas acho que ele não tem a funcionalidade de me entregar o prompt de comando. Estou tentando também usar o Pexpect, mas sem muita sorte.</p>

	Tags: <a href="http://geek.linuxman.pro.br/tag/bash" title="bash" rel="tag">bash</a>, <a href="http://geek.linuxman.pro.br/tag/python" title="python" rel="tag">python</a>, <a href="http://geek.linuxman.pro.br/tag/scripts" title="scripts" rel="tag">scripts</a>, <a href="http://geek.linuxman.pro.br/tag/ssh" title="ssh" rel="tag">ssh</a><br />
]]></content:encoded>
			<wfw:commentRss>http://geek.linuxman.pro.br/geek/desafio-do-beakman/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Nested variables no Bash</title>
		<link>http://geek.linuxman.pro.br/geek/dicas/nested-variables-no-bash</link>
		<comments>http://geek.linuxman.pro.br/geek/dicas/nested-variables-no-bash#comments</comments>
		<pubDate>Sat, 30 May 2009 01:18:49 +0000</pubDate>
		<dc:creator>Eri</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://geek.linuxman.pro.br/?p=1090</guid>
		<description><![CDATA[Não sei ao certo como é o nome em português. Variáveis aninhadas? Me deparei com um problema assim hoje: Eu tinha uma função num script shell que recebia um parâmetro de sucesso ou erro. Eu executava algumas coisas e depois tinha que jogar uns dados no arquivo respectivo. Então inicialmente tinha setado uma variável com [...]]]></description>
			<content:encoded><![CDATA[<p>Não sei ao certo como é o nome em português. Variáveis aninhadas? <img src='http://geek.linuxman.pro.br/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
<p>Me deparei com um problema assim hoje: Eu tinha uma função num script shell que recebia um parâmetro de sucesso ou erro. Eu executava algumas coisas e depois tinha que jogar uns dados no arquivo respectivo.</p>
<p>Então inicialmente tinha setado uma variável com os paths dos caminhos:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">ARQUIVO_SUCESSO</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>sucesso
<span style="color: #007800;">ARQUIVO_ERRO</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>erro</pre></td></tr></table></div>

<p>Minha função recebia o status como o primeiro argumento ($1) e por isso depois de processar eu precisaria de algo assim:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;batatinha&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$ARQUIVO_</span><span style="color: #007800;">$1</span></pre></td></tr></table></div>

<p>Mas logo percebi que isso não funciona. A solução, no entanto, é simples:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;batatinha&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span>  $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #7a0874; font-weight: bold;">echo</span> \<span style="color: #007800;">$ARQUIVO_</span><span style="color: #007800;">$1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<p>Anotem ai na caixa de truques do Bash.</p>

	Tags: <a href="http://geek.linuxman.pro.br/tag/bash" title="bash" rel="tag">bash</a>, <a href="http://geek.linuxman.pro.br/tag/scripts" title="scripts" rel="tag">scripts</a><br />
]]></content:encoded>
			<wfw:commentRss>http://geek.linuxman.pro.br/geek/dicas/nested-variables-no-bash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arrays associativos no Bash 4.0</title>
		<link>http://geek.linuxman.pro.br/geek/arrays-associativos-no-bash-40</link>
		<comments>http://geek.linuxman.pro.br/geek/arrays-associativos-no-bash-40#comments</comments>
		<pubDate>Wed, 25 Feb 2009 17:45:09 +0000</pubDate>
		<dc:creator>Eri</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://geek.linuxman.pro.br/?p=798</guid>
		<description><![CDATA[O Bash 4.0 foi lançado na segunda-feira e trouxe uma nova capacidade que sempre vejo as pessoas pedindo:  Arrays associativos. E funciona que é uma maravilha&#8230; $ echo $BASH_VERSION 4.0.0&#40;1&#41;-release $ declare -A COMIDA $ COMIDA&#91;Arroz&#93;=Branco $ COMIDA&#91;Feijao&#93;=Tutu $ COMIDA&#91;Ovo&#93;=Frito $ COMIDA&#91;CARNE&#93;=Bife $ echo ${COMIDA[@]} Bife Tutu Branco Frito $ echo ${COMIDA[Arroz]} Branco $ echo [...]]]></description>
			<content:encoded><![CDATA[<p>O <a href="http://www.mail-archive.com/cygwin@cygwin.com/msg94439.html">Bash 4.0 foi lançado</a> na segunda-feira e trouxe uma nova capacidade que sempre vejo as pessoas pedindo:  Arrays associativos.</p>
<p>E funciona que é uma maravilha&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$BASH_VERSION</span>
4.0.0<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>-release
$ <span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #660033;">-A</span> COMIDA
$ COMIDA<span style="color: #7a0874; font-weight: bold;">&#91;</span>Arroz<span style="color: #7a0874; font-weight: bold;">&#93;</span>=Branco
$ COMIDA<span style="color: #7a0874; font-weight: bold;">&#91;</span>Feijao<span style="color: #7a0874; font-weight: bold;">&#93;</span>=Tutu
$ COMIDA<span style="color: #7a0874; font-weight: bold;">&#91;</span>Ovo<span style="color: #7a0874; font-weight: bold;">&#93;</span>=Frito
$ COMIDA<span style="color: #7a0874; font-weight: bold;">&#91;</span>CARNE<span style="color: #7a0874; font-weight: bold;">&#93;</span>=Bife
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${COMIDA[@]}</span>
Bife Tutu Branco Frito
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${COMIDA[Arroz]}</span>
Branco
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${COMIDA[Feijao]}</span>
Tutu
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${COMIDA[Ovo]}</span>
Frito
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${COMIDA[CARNE]}</span>
Bife</pre></div></div>

<p>Mais informações sobre as novas features <a href="http://bash-hackers.org/wiki/doku.php/bash4">aqui</a>.</p>

	Tags: <a href="http://geek.linuxman.pro.br/tag/bash" title="bash" rel="tag">bash</a>, <a href="http://geek.linuxman.pro.br/tag/cli" title="CLI" rel="tag">CLI</a>, <a href="http://geek.linuxman.pro.br/tag/shell" title="shell" rel="tag">shell</a><br />
]]></content:encoded>
			<wfw:commentRss>http://geek.linuxman.pro.br/geek/arrays-associativos-no-bash-40/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Truques no Bash</title>
		<link>http://geek.linuxman.pro.br/geek/truques-no-bash</link>
		<comments>http://geek.linuxman.pro.br/geek/truques-no-bash#comments</comments>
		<pubDate>Thu, 15 Jan 2009 14:08:34 +0000</pubDate>
		<dc:creator>Eri</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://geek.linuxman.pro.br/?p=641</guid>
		<description><![CDATA[Alguns truques para facilitar o seu dia-a-dia na linha de comando: !$ Representa a última parte do último comando executado. Exemplo: $ grep macarrao comidas.txt macarrao $  cat !$ cat comidas.txt arroz feijao batata frita macarrao Expansão automática Expande automaticamente os valores entre chaves. Uma mão na roda para loops: $ for i in {1..4}; [...]]]></description>
			<content:encoded><![CDATA[<p>Alguns truques para facilitar o seu dia-a-dia na linha de comando:</p>
<h2>!$</h2>
<p>Representa a última parte do último comando executado. Exemplo:</p>
<pre>$ grep macarrao comidas.txt
macarrao</pre>
<pre>$  cat !$
cat comidas.txt
arroz
feijao
batata frita
macarrao</pre>
<h2>Expansão automática</h2>
<p>Expande automaticamente os valores entre chaves. Uma mão na roda para loops:</p>
<pre>$ for i in {1..4}; do echo "i vale $i"; done
i vale 1
i vale 2
i vale 3
i vale 4</pre>
<p>Também funciona com letras:</p>
<pre>$ for i in {a..d}; do echo "i vale $i"; done
i vale a
i vale b
i vale c
i vale d</pre>
<p>E pode ser útil em situações assim:</p>
<pre>$ mkdir -p diretorio{a..c}/sub-diretorio{w..z}</pre>
<pre>$ find .
.
./diretorioc
./diretorioc/sub-diretoriow
./diretorioc/sub-diretoriox
./diretorioc/sub-diretorioz
./diretorioc/sub-diretorioy
./diretoriob
./diretoriob/sub-diretoriow
./diretoriob/sub-diretoriox
./diretoriob/sub-diretorioz
./diretoriob/sub-diretorioy
./diretorioa
./diretorioa/sub-diretoriow
./diretorioa/sub-diretoriox
./diretorioa/sub-diretorioz
./diretorioa/sub-diretorioy</pre>
<h2>^antigo^novo</h2>
<p>Executa o último comando substituindo o valor antigo pelo novo. Exemplo:</p>
<pre>$ cat /etb/lsb-release
cat: /etb/lsb-release: No such file or directory</pre>
<pre>$ ^b^c
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.10
DISTRIB_CODENAME=intrepid
DISTRIB_DESCRIPTION="Ubuntu 8.10"</pre>
<h2>!!</h2>
<p>Reexecuta o último comando. Útil quando você esqueceu algo, como o sudo na frente do comando. Exemplo:</p>
<pre>$ whoami
user</pre>
<pre>$ sudo !!
sudo whoami
root</pre>
<p>Mais truques e dicas <a href="http://samrowe.com/wordpress/advancing-in-the-bash-shell/">aqui</a>.</p>

	Tags: <a href="http://geek.linuxman.pro.br/tag/bash" title="bash" rel="tag">bash</a>, <a href="http://geek.linuxman.pro.br/tag/cli" title="CLI" rel="tag">CLI</a>, <a href="http://geek.linuxman.pro.br/tag/linux" title="linux" rel="tag">linux</a>, <a href="http://geek.linuxman.pro.br/tag/shell" title="shell" rel="tag">shell</a>, <a href="http://geek.linuxman.pro.br/tag/unix" title="unix" rel="tag">unix</a><br />
]]></content:encoded>
			<wfw:commentRss>http://geek.linuxman.pro.br/geek/truques-no-bash/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Estou entre os maiores do shell scripting</title>
		<link>http://geek.linuxman.pro.br/geek/estou-entre-os-maiores-do-shell-scripting</link>
		<comments>http://geek.linuxman.pro.br/geek/estou-entre-os-maiores-do-shell-scripting#comments</comments>
		<pubDate>Wed, 05 Nov 2008 00:11:15 +0000</pubDate>
		<dc:creator>Eri</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Humor]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://geek.linuxman.pro.br/?p=511</guid>
		<description><![CDATA[Na foto (esquerda pra direita): Eu, Júlio Cézar Neves e Aurélio Marinho Jargas. Autores de &#8220;Programacão Shell Linux&#8221; e  Shell Script Profissional. Entenderam? &#8220;Entre os maiores&#8221;? Hein? Hein? Macaco do Chongas rulez. Voltamos à programação normal. Tags: bash, Humor, scripts, shell]]></description>
			<content:encoded><![CDATA[<p><a href="http://geek.linuxman.pro.br/wp-content/uploads/2008/11/dsc00561.jpg"><img class="aligncenter size-full wp-image-512" title="dsc00561" src="http://geek.linuxman.pro.br/wp-content/uploads/2008/11/dsc00561.jpg" alt="" width="500" height="375" /></a></p>
<p>Na foto (esquerda pra direita): Eu, <a href="http://twiki.softwarelivre.org/TWikiBar/WebHome">Júlio Cézar Neves</a> e <a href="http://aurelio.net/">Aurélio Marinho Jargas</a>. Autores de <a href="http://www.submarino.com.br/produto/1/21390807/programacao+shell+linux">&#8220;Programacão Shell Linux&#8221;</a> e  <a href="http://www.shellscript.com.br/">Shell Script Profissional</a>.</p>
<p>Entenderam? &#8220;Entre os maiores&#8221;? Hein? Hein?</p>
<p><a href="http://geek.linuxman.pro.br/wp-content/uploads/2008/11/67bd70b8.jpg"><img class="aligncenter size-full wp-image-513" title="67bd70b8" src="http://geek.linuxman.pro.br/wp-content/uploads/2008/11/67bd70b8.jpg" alt="" width="260" height="295" /></a></p>
<p>Macaco do <a href="http://www.chongas.com.br">Chongas</a> rulez. Voltamos à programação normal.</p>

	Tags: <a href="http://geek.linuxman.pro.br/tag/bash" title="bash" rel="tag">bash</a>, <a href="http://geek.linuxman.pro.br/tag/humor" title="Humor" rel="tag">Humor</a>, <a href="http://geek.linuxman.pro.br/tag/scripts" title="scripts" rel="tag">scripts</a>, <a href="http://geek.linuxman.pro.br/tag/shell" title="shell" rel="tag">shell</a><br />
]]></content:encoded>
			<wfw:commentRss>http://geek.linuxman.pro.br/geek/estou-entre-os-maiores-do-shell-scripting/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>checkout</title>
		<link>http://geek.linuxman.pro.br/codes/checkout</link>
		<comments>http://geek.linuxman.pro.br/codes/checkout#comments</comments>
		<pubDate>Tue, 21 Oct 2008 17:35:37 +0000</pubDate>
		<dc:creator>Eri</dc:creator>
				<category><![CDATA[codes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[servidor]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://geek.linuxman.pro.br/?p=493</guid>
		<description><![CDATA[À medida que você precisa administrar mais e mais servidores, cada um rodando seus serviços e daemons específicos fica mais complicado saber o que está em casa máquina. Pior ainda quando você precisa que alguém com menos experiência ou conhecimento (aka suporte nível 1) verifique para você o estado do servidor. A idéia é então [...]]]></description>
			<content:encoded><![CDATA[<p>À medida que você precisa administrar mais e mais servidores, cada um rodando seus serviços e daemons específicos fica mais complicado saber o que está em casa máquina.</p>
<p>Pior ainda quando você precisa que alguém com menos experiência ou conhecimento (aka suporte nível 1) verifique para você o estado do servidor.</p>
<p>A idéia é então centralizar essa checagem num único script, simples e funcional, para facilitar a sua vida e a dos outros admins.</p>
<p>Tenho certeza que já existem por ai trocentos scripts/programas/whatever para fazer isso, mas eu estava entediado e precisava usar um pouco de Perl para não enferrujar completamente (É&#8230; ando usando só Python e Bash).</p>
<p>O script <a href="http://geek.linuxman.pro.br/arquivos/checkout">está disponível aqui</a> e está bem documentado e é de simples entendimento.</p>
<p>Basta criar um arquivo /etc/checks.txt contendo o que você esperaria ver rodando normalmente e está feito.</p>

	Tags: <a href="http://geek.linuxman.pro.br/tag/bash" title="bash" rel="tag">bash</a>, <a href="http://geek.linuxman.pro.br/tag/linux" title="linux" rel="tag">linux</a>, <a href="http://geek.linuxman.pro.br/tag/perl" title="perl" rel="tag">perl</a>, <a href="http://geek.linuxman.pro.br/tag/python" title="python" rel="tag">python</a>, <a href="http://geek.linuxman.pro.br/tag/servidor" title="servidor" rel="tag">servidor</a>, <a href="http://geek.linuxman.pro.br/tag/solaris" title="solaris" rel="tag">solaris</a>, <a href="http://geek.linuxman.pro.br/tag/sysadmin" title="sysadmin" rel="tag">sysadmin</a><br />
]]></content:encoded>
			<wfw:commentRss>http://geek.linuxman.pro.br/codes/checkout/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mkfile for Linux</title>
		<link>http://geek.linuxman.pro.br/codes/mkfile-for-linux</link>
		<comments>http://geek.linuxman.pro.br/codes/mkfile-for-linux#comments</comments>
		<pubDate>Fri, 03 Oct 2008 17:20:54 +0000</pubDate>
		<dc:creator>Eri</dc:creator>
				<category><![CDATA[codes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://geek.linuxman.pro.br/?p=458</guid>
		<description><![CDATA[Eu não conhecia o mkfile do Solaris até ontem, mas foi só usar um pouco e deu pra ver que é muito mais prático e rápido do que ficar utilizando o dd no Linux. Não sei os meus 2 leitores geeks (já que meu pai, minha mãe e minha esposa &#8211; meus outros 3 leitores [...]]]></description>
			<content:encoded><![CDATA[<p>Eu não conhecia o mkfile do Solaris até ontem, mas foi só usar um pouco e deu pra ver que é muito mais prático e rápido do que ficar utilizando o <strong>dd</strong> no Linux.</p>
<p>Não sei os meus 2 leitores geeks (já que meu pai, minha mãe e minha esposa &#8211; meus outros 3 leitores &#8211; não se encaixam nesta categoria), mas eu tenho que olhar o man ou o google toda vez que preciso criar um arquivo em branco com o dd. Tenho algum tipo de bloqueio com aquela sintaxe chata dele.</p>
<p>Então resolvi perder uns minutos e fazer um mkfile for Linux, em bash script mesmo. Divirtam-se.</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;">#=============================================================================</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># mkfile - bash implementation of Solaris' mkfile tool for Linux</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Usage:  mkfile [-v] size [g | k | b | m] filename</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   Eri Ramos Bastos</span>
<span style="color: #666666; font-style: italic;">#   http://geek.linuxman.pro.br</span>
<span style="color: #666666; font-style: italic;">#=============================================================================</span>
&nbsp;
<span style="color: #007800;">progname</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">function</span> die <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$progname</span>: $1&quot;</span>; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #800000;">${2:-1}</span>  ; <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #007800;">VERBOSE</span>=<span style="color: #ff0000;">&quot;&amp;gt;/dev/null 2&amp;gt;&amp;amp;1&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> Help <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: mkfile [-v] &amp;lt;size&amp;gt;[g|k|b|m] &amp;lt;name1&amp;gt; [&amp;lt;name2&amp;gt;] ...&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -v    Verbose&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>    <span style="color: #666666; font-style: italic;"># ----------  end of function Help  ----------</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------</span>
<span style="color: #666666; font-style: italic;">#  Check number of command line arguments and set verbose</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
Help; die <span style="color: #ff0000;">&quot;Insufficient number of arguments&quot;</span>
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">2</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;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> = <span style="color: #ff0000;">&quot;-v&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;  <span style="color: #007800;">VERBOSE</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">SIZE</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$1&quot;</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>kmg<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>KMG<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> ; <span style="color: #7a0874; font-weight: bold;">shift</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${@}</span>
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>zero <span style="color: #007800;">of</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span> <span style="color: #007800;">count</span>=<span style="color: #000000;">1</span> <span style="color: #007800;">bs</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$SIZE</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERBOSE</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; Help <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; die <span style="color: #ff0000;">&quot;Error creating file <span style="color: #007800;">$file</span>&quot;</span> <span style="color: #000000;">2</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>


	Tags: <a href="http://geek.linuxman.pro.br/tag/bash" title="bash" rel="tag">bash</a>, <a href="http://geek.linuxman.pro.br/tag/coding" title="coding" rel="tag">coding</a>, <a href="http://geek.linuxman.pro.br/tag/linux" title="linux" rel="tag">linux</a>, <a href="http://geek.linuxman.pro.br/tag/scripts" title="scripts" rel="tag">scripts</a>, <a href="http://geek.linuxman.pro.br/tag/shell" title="shell" rel="tag">shell</a>, <a href="http://geek.linuxman.pro.br/tag/solaris" title="solaris" rel="tag">solaris</a><br />
]]></content:encoded>
			<wfw:commentRss>http://geek.linuxman.pro.br/codes/mkfile-for-linux/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Utilizando o VIM como IDE para o Bash</title>
		<link>http://geek.linuxman.pro.br/geek/dicas/utilizando-o-vim-como-ide-para-o-bash</link>
		<comments>http://geek.linuxman.pro.br/geek/dicas/utilizando-o-vim-como-ide-para-o-bash#comments</comments>
		<pubDate>Tue, 09 Sep 2008 15:11:51 +0000</pubDate>
		<dc:creator>Eri</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://geek.linuxman.pro.br/?p=430</guid>
		<description><![CDATA[Como já devem saber eu sou da turminha do vi. Nada contra o Emacs, lógico, mas vi é vi. O relacionamento com ele nunca começa bem. Lembro-me que a primeira vez que abri o vi, num SCO Unix, o único jeito que consegui sair do editor foi rebootando a máquina. Eu não tinha nem idéia [...]]]></description>
			<content:encoded><![CDATA[<p>Como já devem saber <a href="http://geek.linuxman.pro.br/tag/vi">eu sou da turminha do vi</a>. Nada contra o Emacs, lógico, mas vi é vi.<br />
O relacionamento com ele nunca começa bem. Lembro-me que a primeira vez que abri o vi, num SCO Unix, o único jeito que consegui sair do editor foi rebootando a máquina. Eu não tinha nem idéia de que bastava um ESC:q! para cumprir a tarefa. Mas passados 11 anos ou mais deste início traumático, posso dizer que me dou bem com o editor hoje em dia, utilizando-o inclusive para escrever posts no meu blog, como neste momento o faço.</p>
<p>Às vezes o que sentia falta era de alguma coisa para facilitar minha vida quando estava fazendo meus scripts. Alguns pedaços de código você usa de novo, de novo e de novo. E é um saco ficar redigitando.<br />
Importar para dentro do arquivo atual (ESC:r /path/arquivo) ajuda, mas não resolve.</p>
<h2>A solução</h2>
<p>Pesquisando achei o sensacional <a href="http://www.vim.org/scripts/script.php?script_id=365">BASH-IDE</a> para vim. Resolveu todos os meus problemas, exceto a falta de competência como programador.<br />
Utilizando o BASH-IDE podemos configurar um template para novos arquivos, de forma que sempre que abro um novo arquivo .sh no vim ele já adiciona o cabeçalho com informação sobre o autor, data, tag $id$ pro cvs e algumas variáveis e funções que eu coloco em todos os meus script.</p>
<p>O autor do BASH-IDE foi cuidadoso para facilitar a documentação de forma que vários atalhos já são auto-documentados.<br />
Uma nova função criada utilizando o BASH-IDE automaticamente terá o seguinte aspecto:</p>
<pre>function teste ()
{

}    # ----------  end of function teste  ----------</pre>
<p>E ao chamar o atalho para documentação de função você recebe este template:</p>
<pre>#===  FUNCTION  ================================================================
#          NAME:
#   DESCRIPTION:
#    PARAMETERS:
#       RETURNS:
#===============================================================================</pre>
<p>Como tudo é baseado em arquivos texto, as customizações só dependem da sua boa vontade. E ainda vem com um uma cheat sheet em pdf pronta para imprimir e pendurar na sua baia! <img src='http://geek.linuxman.pro.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Boa diversão</p>

	Tags: <a href="http://geek.linuxman.pro.br/tag/bash" title="bash" rel="tag">bash</a><br />
]]></content:encoded>
			<wfw:commentRss>http://geek.linuxman.pro.br/geek/dicas/utilizando-o-vim-como-ide-para-o-bash/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

