<?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>KodeGeek &#187; Añadir nueva etiqueta</title>
	<atom:link href="http://kodegeek.com/blog/tag/anadir-nueva-etiqueta/feed/" rel="self" type="application/rss+xml" />
	<link>http://kodegeek.com/blog</link>
	<description>Programación, fitness, interés geek</description>
	<lastBuildDate>Sun, 05 Feb 2012 19:12:12 +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>Bitacoras.com apoyando a StupidZombie</title>
		<link>http://kodegeek.com/blog/2009/06/03/bitacorascom-apoyando-a-stupidzombie/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bitacorascom-apoyando-a-stupidzombie</link>
		<comments>http://kodegeek.com/blog/2009/06/03/bitacorascom-apoyando-a-stupidzombie/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 00:11:53 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[kodegeek]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[Añadir nueva etiqueta]]></category>
		<category><![CDATA[bitacoras.com]]></category>
		<category><![CDATA[stupidzombie]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=1843</guid>
		<description><![CDATA[¡Genial!. Un millón de gracias a los chamos de bitacoras.com, los cuales hablan sobre StupidZombie!: http://bitacoras.com/noticias/archivos/stupidzombie-aplicacion-de-escritorio-para-envio-de-ping.php Ahora a dominar el mundo Pinki]]></description>
			<content:encoded><![CDATA[<p>¡Genial!. Un millón de gracias a los chamos de bitacoras.com, los cuales hablan sobre StupidZombie!:</p>
<p><a href="http://bitacoras.com/noticias/archivos/stupidzombie-aplicacion-de-escritorio-para-envio-de-ping.php" target="_self">http://bitacoras.com/noticias/archivos/stupidzombie-aplicacion-de-escritorio-para-envio-de-ping.php</a></p>
<p>Ahora a dominar el mundo Pinki <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2009/06/03/bitacorascom-apoyando-a-stupidzombie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Construyendo un servidor de logs usando Netcat, tail y Bash</title>
		<link>http://kodegeek.com/blog/2009/03/14/construyendo-un-servidor-de-logs-usando-netcat-tail-y-bash/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=construyendo-un-servidor-de-logs-usando-netcat-tail-y-bash</link>
		<comments>http://kodegeek.com/blog/2009/03/14/construyendo-un-servidor-de-logs-usando-netcat-tail-y-bash/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 13:26:12 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[venezuela]]></category>
		<category><![CDATA[Añadir nueva etiqueta]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=1673</guid>
		<description><![CDATA[Me toco entre estos días escribir un hack (no por lo malo sino por lo rápido que tenia que hacerlo) un servidor que debía proporcional el contenido de una bitacora la cual crece de manera continua durante el día. El grupo que nos pidio esto es de auditoria, lo cual implica que no debe perderse [...]]]></description>
			<content:encoded><![CDATA[<p>Me toco entre estos días escribir un hack (no por lo malo sino por lo rápido que tenia que hacerlo) un servidor que debía proporcional el contenido de una bitacora la cual crece de manera continua durante el día. El grupo que nos pidio esto es de auditoria, lo cual implica que no debe perderse información.</p>
<p>Primero les muestro el código del programa y explico como funciona:</p>

<div class="wp_codebox"><table><tr id="p16732"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code" id="p1673code2"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># author: josevnz@kodegeek.com</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-o</span> monitor
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #660033;">-a</span> pids
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #660033;">-r</span> <span style="color: #007800;">SCRIPT</span>=<span style="color: #800000;">${0##*/}</span>
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #660033;">-r</span> <span style="color: #007800;">FIFO</span>=<span style="color: #ff0000;">&quot;/tmp/<span style="color: #007800;">$SCRIPT</span>-$$.fifo&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&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;Please provide the file to tail and try again&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">192</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$2&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;Please provide port and try again&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">192</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">trap</span> cleanup <span style="color: #7a0874; font-weight: bold;">exit</span> INT TERM
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FIFO</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #c20cb9; font-weight: bold;">mkfifo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FIFO</span>&quot;</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: #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;">then</span>
                <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FIFO</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
<span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #ff0000;">&quot;test -e <span style="color: #007800;">$FIFO</span> &amp;&amp; rm -f <span style="color: #007800;">$FIFO</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">exit</span> INT TERM
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FIFO</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> netcat <span style="color: #660033;">-v</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-l</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$2</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FIFO</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #ff0000;">&quot;kill -9 $! $$&quot;</span> <span style="color: #7a0874; font-weight: bold;">exit</span> INT TERM</pre></td></tr></table></div>

<p>La idea es revisar los contenidos del archivo usando &#8216;tail -F&#8217;. La opción &#8216;-F&#8217; le dice a tail que reintente si tiene problemas eyendo el archivo; De allí redirigimos los contenidos a una cola (FIFO, first in first out) en Unix la cual garantiza que aunque el servidor TCP muera los datos estaran allí listos para ser enviados al cliente. Dejamos a tail corriendo en segundo plano&#8230;</p>
<p>El siguiente paso es arrancar nuestro servidor TCP. <a href="http://netcat.sourceforge.net/" target="_blank">Netcat</a> recibe los contenidos de la cola que creamos en el paso anterior. Fijense como lo encerramos en un ciclo infinito ya que si el cliente se muere (o desconecta por otra razón) Netcat cerrará la conexión.</p>
<p>Finalmente le decimos al script que mate todos los procesos hijos o el mismo programa si decidimos matar al servidor o nos matan el proceso.</p>
<p>Bueno, aqui les muestro como correr el servidor:</p>
<blockquote><p>auyan:~ josevnz$ ./nettail fakelog.log 9000<br />
Listening on any address 9000 (cslistener)<br />
Connection from 127.0.0.1:50754<br />
Total received bytes: 0<br />
Total sent bytes: 432<br />
Listening on any address 9000 (cslistener)<br />
Connection from 127.0.0.1:50819</p></blockquote>
<p>Y un ejemplo de como conectarse:</p>
<blockquote><p>auyan:~ josevnz$ nc -v -v -v localhost 9000<br />
nc: connect to localhost port 9000 (tcp) failed: Connection refused<br />
Connection to localhost 9000 port [tcp/cslistener] succeeded!<br />
This is a kodegeek test: Sat Mar 14 00:02:15 EDT 2009<br />
This is a kodegeek test: Sat Mar 14 00:02:45 EDT 2009<br />
This is a kodegeek test: Sat Mar 14 00:03:15 EDT 2009<br />
This is a kodegeek test: Sat Mar 14 00:03:45 EDT 2009<br />
This is a kodegeek test: Sat Mar 14 00:04:15 EDT 2009<br />
This is a kodegeek test: Sat Mar 14 00:04:45 EDT 2009<br />
This is a kodegeek test: Sat Mar 14 00:05:15 EDT 2009<br />
This is a kodegeek test: Sat Mar 14 00:05:45 EDT 2009<br />
This is a kodegeek test: Sat Mar 14 00:06:15 EDT 2009</p></blockquote>
<p>Espero les guste esta solución de 5 minutos <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Veneblogs: <a rel="tag" href="http://www.veneblogs.com/etiquetas/bash">bash</a>, <a rel="tag" href="http://www.veneblogs.com/etiquetas/netcat">netcat</a>, <a rel="tag" href="http://www.veneblogs.com/etiquetas/tail">tail</a>, <a rel="tag" href="http://www.veneblogs.com/etiquetas/kodegeek">kodegeek</a>, <a rel="tag" href="http://www.veneblogs.com/etiquetas/server">server</a></p>
<p>Blogalaxia: <a rel="tag" href="http://www.blogalaxia.com/tags/bash">bash</a>, <a rel="tag" href="http://www.blogalaxia.com/tags/netcat">netcat</a>, <a rel="tag" href="http://www.blogalaxia.com/tags/tail">tail</a>, <a rel="tag" href="http://www.blogalaxia.com/tags/kodegeek">kodegeek</a>, <a rel="tag" href="http://www.blogalaxia.com/tags/server">server</a></p>
<p>To2blogs: <a rel="tag" href="http://www.to2blogs.com/tag/bash">bash</a>, <a rel="tag" href="http://www.to2blogs.com/tag/netcat">netcat</a>, <a rel="tag" href="http://www.to2blogs.com/tag/tail">tail</a>, <a rel="tag" href="http://www.to2blogs.com/tag/kodegeek">kodegeek</a>, <a rel="tag" href="http://www.to2blogs.com/tag/server">server</a></p>
<p>Technorati: <a rel="tag" href="http://technorati.com/tag/bash">bash</a>, <a rel="tag" href="http://technorati.com/tag/netcat">netcat</a>, <a rel="tag" href="http://technorati.com/tag/tail">tail</a>, <a rel="tag" href="http://technorati.com/tag/kodegeek">kodegeek</a>, <a rel="tag" href="http://technorati.com/tag/server">server</a></p>
<p>Del.icio.us: <a rel="tag" href="http://del.icio.us/tag/bash">bash</a>, <a rel="tag" href="http://del.icio.us/tag/netcat">netcat</a>, <a rel="tag" href="http://del.icio.us/tag/tail">tail</a>, <a rel="tag" href="http://del.icio.us/tag/kodegeek">kodegeek</a>, <a rel="tag" href="http://del.icio.us/tag/server">server</a></pre>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2009/03/14/construyendo-un-servidor-de-logs-usando-netcat-tail-y-bash/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

