<?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>{Dev Tricks} &#187; unix</title>
	<atom:link href="http://dev-tricks.net/category/unix/feed" rel="self" type="application/rss+xml" />
	<link>http://dev-tricks.net</link>
	<description>Blogging developper tips and tricks</description>
	<lastBuildDate>Thu, 17 May 2012 13:09:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>ashttp: vt100 screen scraping exported over HTTP</title>
		<link>http://dev-tricks.net/ashttp-vt100-screen-scraping-exported-over-http</link>
		<comments>http://dev-tricks.net/ashttp-vt100-screen-scraping-exported-over-http#comments</comments>
		<pubDate>Sat, 27 Aug 2011 13:08:21 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=358</guid>
		<description><![CDATA[Originally wrote for logtop I just wrote a vt100 screen scraper that listen to a port and serve the screen over HTTP. Basically, you want a `top` (or logtop ;-) ) to be displayed in your website back office ? &#8230; <a href="http://dev-tricks.net/ashttp-vt100-screen-scraping-exported-over-http">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Originally wrote for <a href="https://github.com/JulienPalard/logtop" title="https://github.com/JulienPalard/logtop">logtop</a> I just wrote a vt100 screen scraper that listen to a port and serve the screen over HTTP.</p>
<p>Basically, you want a `top` (or logtop ;-) ) to be displayed in your website back office ? But top outputs in your terminal and you don&#8217;t know how to capture it ? Use ashttp, like this :</p>
<pre lang=bash>
$ ashttp -p 8080 top
</pre>
<p>And then just open the port 8080 with an HTTP client and enjoy (typing some F5&#8230;) :</p>
<p><img src="http://dev-tricks.net/wp-content/uploads/2011/08/ashttp1.png" alt="" title="ashttp-capture" width="668" height="424" class="aligncenter size-full wp-image-362" /></p>
<p>You can find the code on <a href="https://github.com/JulienPalard/ashttp" title="https://github.com/JulienPalard/ashttp"> my github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/ashttp-vt100-screen-scraping-exported-over-http/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>nfsmount : rpc failed: 2</title>
		<link>http://dev-tricks.net/nfsmount_rpc_failed_2</link>
		<comments>http://dev-tricks.net/nfsmount_rpc_failed_2#comments</comments>
		<pubDate>Mon, 18 Apr 2011 12:45:03 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=331</guid>
		<description><![CDATA[For those, here on the internet, asking themselves what is this f*cking `rpc failed: 2` while mounting an NFS, i&#8217;ts possible that teh response is here : Your NFS client, trying to mount the NFS share will use RPC to &#8230; <a href="http://dev-tricks.net/nfsmount_rpc_failed_2">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For those, here on the internet, asking themselves what is this f*cking `rpc failed: 2` while mounting an NFS, i&#8217;ts possible that teh response is here :</p>
<p>Your NFS client, trying to mount the NFS share will use RPC to communicate with the serveur, il will go like :</p>
<p>> PORTMAP GETPORT(Program: NFS, Version: 3, Proto: TCP)<br />
< PORTMAP Port: 2049<br />
> PORTMAP GETPORT(Program: MOUNT, Version: 3, Proto: TCP)<br />
< PORTMAP Port 49066<br />
> MOUNT MNT(Program Version: 3, Path: /srv/nfsroot/ )<br />
< MOUNT Reply error 2, "remote can't support version #", Program Version (Minimum): 1, Program Version (Maximum): 2</p>
<p>You can see that the response is "remote can't support version #" and we should have found this solution in the <a href="http://www.ietf.org/rfc/rfc1831.txt">RFC 1831 (RPCv2)</a> stating :</p>
<pre>
  Given that a call message was accepted, the following is the status
   of an attempt to call a remote procedure.

      enum accept_stat {
         SUCCESS       = 0, /* RPC executed successfully             */
         PROG_UNAVAIL  = 1, /* remote hasn't exported program        */
         PROG_MISMATCH = 2, /* remote can't support version #        */
         PROC_UNAVAIL  = 3, /* program can't support procedure       */
         GARBAGE_ARGS  = 4, /* procedure can't decode params         */
         SYSTEM_ERR    = 5  /* errors like memory allocation failure */
      };
</pre>
<p>So the problem is you client is asking for a NFS version greater that your server runs &#8230; but if your server is running NFS v3, check a `ps aux | grep [r]pc.mountd` for :</p>
<p>root      1411  0.0  0.0  18808  1036 ?        Ss   Apr15   0:00 /usr/sbin/rpc.mountd &#8211;manage-gids &#8211;no-nfs-version 3</p>
<p>Did you catch the &#8211;no-nfs-version 3 ? If your server is compiled with NFSv3 support, drop the &#8211;no-nfs-version 3 in your configuration and it should work !</p>
<p>Enjoy !</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/nfsmount_rpc_failed_2/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Yauib : Yet another useless IRC Bot !</title>
		<link>http://dev-tricks.net/yauib-yet-another-useless-irc-bot</link>
		<comments>http://dev-tricks.net/yauib-yet-another-useless-irc-bot#comments</comments>
		<pubDate>Sun, 27 Mar 2011 21:40:58 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=276</guid>
		<description><![CDATA[After 2 years of &#8230; non blogging &#8230; I&#8217;m back ! This time I stopped C# (Oh yeah !) and I&#8217;m writing a lot of Python ! (Oh YEAH !) So to say HELLO I&#8217;ll present something useless : My &#8230; <a href="http://dev-tricks.net/yauib-yet-another-useless-irc-bot">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After 2 years of &#8230; non blogging &#8230; I&#8217;m back !<br />
This time I stopped C# (Oh yeah !) and I&#8217;m writing a lot of Python ! (Oh YEAH !)</p>
<p>So to say HELLO I&#8217;ll present something useless : My Python IRC Bot. But this article should be usefull, so I&#8217;ll speak about the Unix Philosophy :<br />
As Doug McIlroy said :</p>
<blockquote><p>This is the Unix philosophy: Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
</p></blockquote>
<p>So my Python Bot is wrote like this, only ~200 lines of Python it has only two interfaces, and they are simple.</p>
<p>The first step is to start the bot :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>ircbot.py connect <span style="color: #ff0000;">'server'</span> <span style="color: #ff0000;">'#chan'</span> <span style="color: #ff0000;">'nickname'</span></pre></div></div>

<p>Ok the bot is connected to a chan, now you have to write some hooks, in yauib every action raise a hook in the &#8216;hooks&#8217; directory, you can write a hook in any language you want. As a good start point I wrote a default hook for received messages in hook/pubmsg, simplified like this :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh -f</span>
<span style="color: #007800;">s_login</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(echo &quot;$1&quot; | sed 's#/#__SLASH__#g')</span>&quot;</span>
<span style="color: #007800;">s_host</span>=<span style="color: #ff0000;">&quot;$2&quot;</span>
<span style="color: #007800;">t_login</span>=<span style="color: #ff0000;">&quot;$3&quot;</span>
<span style="color: #007800;">t_host</span>=<span style="color: #ff0000;">&quot;$4&quot;</span>
<span style="color: #7a0874; font-weight: bold;">shift</span> <span style="color: #000000;">4</span>
<span style="color: #007800;">arguments</span>=<span style="color: #ff0000;">&quot;$*&quot;</span>
<span style="color: #007800;">command</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${1%% *}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s#/#__SLASH__#g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-x</span> <span style="color: #ff0000;">&quot;commands/<span style="color: #007800;">$command</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">args</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;">sed</span> <span style="color: #ff0000;">'s/^ *[^ ]* *//g'</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
    commands<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$command</span> <span style="color: #007800;">$args</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>You should read : &#8220;When a message is received, the command in commands/[1st word of the message] is executed.&#8221;</p>
<p>So now you can start to write simple commands in the commands folder, like the command say :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$*&quot;</span></pre></div></div>

<p>This command is 17 chars long, and now, without restarting your bot, try to make it say something on the channel :<br />
you> say hello<br />
bot> hello</p>
<p>An now you can start to write dauting ones &#8230;. like &#8230; display a readeable calendar of the current month like :</p>
<pre>
     March 2011
Su Mo Tu We Th Fr Sa
       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
</pre>
<p>Ready ?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #c20cb9; font-weight: bold;">cal</span></pre></div></div>

<p>As the binary cal is installed on you machine, (windows user, you can leave, now), that&#8217;s all, your&#8217;re done &#8230; sorry, it just work :p</p>
<p>Et voilà !</p>
<p>You have to keep the UNIX philosophy in mind :<br />
 &#8211; Everything is a file<br />
 &#8211; Write programs that do one thing and do it well</p>
<p>And you&#8217;ll be happy developers !</p>
<p>PS: You can download / contribute to Yauib on https://github.com/JulienPalard/yauib</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/yauib-yet-another-useless-irc-bot/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Exclude directories from recursive grep</title>
		<link>http://dev-tricks.net/exclude-directories-matching-from-recursive-grep</link>
		<comments>http://dev-tricks.net/exclude-directories-matching-from-recursive-grep#comments</comments>
		<pubDate>Sun, 16 Nov 2008 14:20:13 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[unix]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=53</guid>
		<description><![CDATA[How often are you using grep in subversionned folders like that : grep -rni foobar . &#124; grep -v .svn Upgrade to grep 2.5.3 and use (alias it ?) grep -rni --exclude-dir .svn foobar . (or &#8230; stop using SVN &#8230; <a href="http://dev-tricks.net/exclude-directories-matching-from-recursive-grep">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>How often are you using grep in subversionned folders like that :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-rni</span> foobar . <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> .svn</pre></div></div>

<p>Upgrade to grep 2.5.3 and use (alias it ?)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-rni</span> <span style="color: #660033;">--exclude-dir</span> .svn foobar .</pre></div></div>

<p>(or &#8230; stop using SVN ! ! !)</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/exclude-directories-matching-from-recursive-grep/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

