<?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>Sakana.fr - A sysadmin&#039;s blog &#187; Dev</title>
	<atom:link href="http://www.sakana.fr/blog/category/dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sakana.fr/blog</link>
	<description>On the fly saving of few useful (?) tech tips</description>
	<lastBuildDate>Thu, 26 Jan 2012 15:30:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>MisterHouse : Setting up &#8220;modes&#8221;</title>
		<link>http://www.sakana.fr/blog/2010/11/13/misterhouse-setting-up-modes/</link>
		<comments>http://www.sakana.fr/blog/2010/11/13/misterhouse-setting-up-modes/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:03:53 +0000</pubDate>
		<dc:creator>Stephane Kattoor</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[home automation]]></category>
		<category><![CDATA[misterhouse]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.sakana.fr/blog/?p=471</guid>
		<description><![CDATA[MisterHouse is a fantastic home automation software with an impressive out-of-the-box feature set, and it only gets better if you know a bit of Perl. You can conveniently set &#8220;modes&#8221;, which are settings with states you can define and use. You can then fire events upon state change, and so are they very useful to [...]<p><a href="http://www.sakana.fr/blog/2010/11/13/misterhouse-setting-up-modes/">MisterHouse : Setting up &#8220;modes&#8221;</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="misterhouse.sourceforge.net" target="_blank">MisterHouse is a fantastic home automation software</a> with an impressive out-of-the-box feature set, and it only gets better if you know a bit of Perl. </p>
<p>You can conveniently set &#8220;modes&#8221;, which are settings with states you can define and use. You can then fire events upon state change, and so are they very useful to define some sort of macros.</p>
<p>A few examples :</p>
<ul>
<li>the &#8220;Security&#8221; mode could be &#8220;on&#8221; or &#8220;off&#8221; : setting it &#8220;on&#8221; would close the shutters and activate the alarm system; setting it &#8220;off&#8221; would do the opposite;</li>
<li>the &#8220;Heating&#8221; mode could be &#8220;day&#8221;, &#8220;night&#8221;, &#8220;frost protection only&#8221; : setting it on &#8220;day&#8221; would set the target temperature to 20⁰C, &#8220;night&#8221; to 15⁰C and &#8220;frost protection only&#8221; to 7⁰C</li>
<li>the &#8220;Cinema&#8221; mode could be &#8220;on&#8221; or &#8220;off&#8221; : setting it to &#8220;on&#8221; would close the blinds and dim the lights; &#8220;off&#8221; would bring those back to their former states.
</ul>
<p>This post will show how to setup a mode, we&#8217;ll use the &#8220;Heating&#8221; mode described above as an example.</p>
<p><span id="more-471"></span></p>
<h4>Coding a mode</h4>
<p>The first thing to know is that a mode is nothing but a <tt>Generic_Item</tt>. By convention, it&#8217;s simpler to use an identifier starting by &#8220;mode_&#8221;.<br />
Here&#8217;s the sample code for the &#8220;Heating&#8221; mode (click to expand):</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p471code3'); return false;">View Code</a> PERL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4713"><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
</pre></td><td class="code" id="p471code3"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$mode_heating</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Generic_Item<span style="color: #339933;">;</span>
<span style="color: #0000ff;">$mode_heating</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">set_states</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'day'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'night'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'off'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>state_changed <span style="color: #0000ff;">$mode_heating</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$heating_mode_state</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$heating_mode_state</span> <span style="color: #339933;">=</span> state <span style="color: #0000ff;">$mode_heating</span><span style="color: #339933;">;</span>
        main<span style="color: #339933;">::</span><span style="color: #006600;">print_log</span> <span style="color: #ff0000;">&quot;Mode = &quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$heating_mode_state</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$heating_mode_state</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;day&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$thermostat_bureau</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setTarget</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #0000ff;">$thermostat_living</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setTarget</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$heating_mode_state</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;night&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$thermostat_bureau</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setTarget</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #0000ff;">$thermostat_living</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setTarget</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$heating_mode_state</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;off&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$thermostat_bureau</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setTarget</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #0000ff;">$thermostat_living</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setTarget</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
set <span style="color: #0000ff;">$mode_heating</span> <span style="color: #ff0000;">&quot;night&quot;</span>       <span style="color: #b1b100;">if</span> time_cron <span style="color: #ff0000;">'00 20 * * *'</span><span style="color: #339933;">;</span>
set <span style="color: #0000ff;">$mode_heating</span> <span style="color: #ff0000;">&quot;day&quot;</span>         <span style="color: #b1b100;">if</span> time_cron <span style="color: #ff0000;">'00 06 * * *'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This code is pretty simple : MisterHouse will take all variable definitions and object creations and will execute them, then put everything else in its main event loop. So here the mode is created and then, in the main event loop, actions will be taken if the state of the mode is changed.<br />
It will also switch the state of the heating mode to day at 6am and to night at 8pm as defined with the &#8220;time_cron&#8221; functionnality.</p>
<h4>Integrating the mode within the web interface</h4>
<p>To have this mode show up in the web interface, you&#8217;ll need to alter the <tt>mh/web/ia5/modes/main.shtml</tt> and add the following row at the end of the &#8220;table&#8221; tag :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p471code4'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4714"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p471code4"><pre class="html" style="font-family:monospace;">&lt;tr&gt;
  &lt;td align='middle'&gt; &lt;!--#include file=&quot;/bin/button_toggle.pl?mode_heating&amp;/ia5/modes/main.shtml&quot;--&gt; &lt;/td&gt;
&lt;/tr&gt;</pre></td></tr></table></div>

<p>If the GD graphics library is installed on your system, is supporting JPEG files and you enabled its use by MisterHouse (<tt>gd = 1</tt> in mh.private.ini), then MisterHouse will generate and display a graphical button with the current state of the mode. If not you&#8217;ll get a text link. No matter what, you can cycle through the different states defined for the mode by simply clicking on it.</p>
<p>If you&#8217;d like to have your own graphical buttons, simply place them into the &#8220;data&#8221; dir (<tt>data_dir</tt> configuration item of the <tt>mh.private.ini</tt>) and name them following the convention &#8220;modename_item_state.jpg&#8221;. For my example modename = mode_heating, and state are &#8220;day&#8221;, &#8220;night&#8221; and &#8220;frost&#8221;, so I&#8217;d need the files &#8220;mode_heating_item_day.jpg&#8221;, &#8220;mode_heating_item_night.jpg&#8221; and &#8220;mode_heating_item_frost.jpg&#8221;.</p>
<h4>References</h4>
<ul>
<li>mh/code/common/mh_control.pl : definition of core MisterHouse modes like  mode_mh (normal/mute/offline), mode_vacation (on/off), mode_security (armed/unarmed), mode_sleep (awake/sleeping parents/sleeping kids). You can use those as working examples for your own modes.</li>
<li>mh/web/ia5/modes directory : html files for the &#8220;modes&#8221; menu web page.</li>
<li>mh/web/bin/button.pl : script which returns the path to the file for a button and generate it if needed.</li>
<li>mh/web/bin/button_toggle.pl : script which generates a link which will toggle an object upon click</li>
</ul>
<p><script type="text/javascript"><!--
google_ad_client = "pub-4571688872511149";
/* 728x90, created 10/17/09 */
google_ad_slot = "0784069657";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><a href="http://www.sakana.fr/blog/2010/11/13/misterhouse-setting-up-modes/">MisterHouse : Setting up &#8220;modes&#8221;</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sakana.fr/blog/2010/11/13/misterhouse-setting-up-modes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook API : Exporting your friends birthdays into vCards format</title>
		<link>http://www.sakana.fr/blog/2010/11/02/facebook-api-exporting-your-friends-birthdays-into-vcards-format/</link>
		<comments>http://www.sakana.fr/blog/2010/11/02/facebook-api-exporting-your-friends-birthdays-into-vcards-format/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 22:47:25 +0000</pubDate>
		<dc:creator>Stephane Kattoor</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.sakana.fr/blog/?p=462</guid>
		<description><![CDATA[The following sample Facebook desktop application exports your friends birthdays in a vCard file format. This file is suitable to be imported into your GMail contacts for example. Here is the script. It&#8217;s pretty simple : ?Download fb-bdays.pl1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [...]<p><a href="http://www.sakana.fr/blog/2010/11/02/facebook-api-exporting-your-friends-birthdays-into-vcards-format/">Facebook API : Exporting your friends birthdays into vCards format</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The following sample Facebook desktop application exports your friends birthdays in a vCard file format. This file is suitable to be imported into your GMail contacts for example. </p>
<p><span id="more-462"></span></p>
<p>Here is the script. It&#8217;s pretty simple :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.sakana.fr/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=462&amp;download=fb-bdays.pl">fb-bdays.pl</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4626"><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
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code" id="p462code6"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> WWW<span style="color: #339933;">::</span><span style="color: #006600;">Facebook</span><span style="color: #339933;">::</span><span style="color: #006600;">API</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Text<span style="color: #339933;">::</span><span style="color: #006600;">vCard</span><span style="color: #339933;">::</span><span style="color: #006600;">Addressbook</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Date<span style="color: #339933;">::</span><span style="color: #006600;">Parse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> WWW<span style="color: #339933;">::</span><span style="color: #006600;">Facebook</span><span style="color: #339933;">::</span><span style="color: #006600;">API</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span>
	desktop <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
	api_key <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'</span><span style="color: #339933;">,</span>
	secret  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$token</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">auth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">create_token</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get_login_url</span><span style="color: #009900;">&#40;</span> auth_token <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$token</span><span style="color: #339933;">,</span> req_perms <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'friends_birthday'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://perldoc.perl.org/functions/system.html"><span style="color: #000066;">system</span></a> <span style="color: #ff0000;">&quot;firefox&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$url</span><span style="color: #339933;">;</span>
<a href="http://perldoc.perl.org/functions/sleep.html"><span style="color: #000066;">sleep</span></a> <span style="color: #cc66cc;">15</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">auth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get_session</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$token</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$response</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fql</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">query</span><span style="color: #009900;">&#40;</span>query <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'select first_name, last_name, birthday from user where uid in (select uid2 from friend where uid1=me())'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ab</span> <span style="color: #339933;">=</span> text<span style="color: #339933;">::</span><span style="color: #006600;">vcard</span><span style="color: #339933;">::</span><span style="color: #006600;">addressbook</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># processes each contact and creates a vCard for it {{{</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$contact</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@$response</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vc</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ab</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">add_vcard</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fn</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$contact</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>first_name<span style="color: #009900;">&#125;</span> <span style="color: #339933;">||</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ln</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$contact</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>last_name<span style="color: #009900;">&#125;</span> <span style="color: #339933;">||</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$ln</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/uc.html"><span style="color: #000066;">uc</span></a> <span style="color: #0000ff;">$ln</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$bd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$contact</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>birthday<span style="color: #009900;">&#125;</span> <span style="color: #339933;">||</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$bd</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/,//g</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #0000ff;">$vc</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fullname</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fn</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$ln</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$bd</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ss</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$mm</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$hh</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$day</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$month</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$year</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$zone</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> strptime<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$bd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #0000ff;">$vc</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">bday</span><span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/join.html"><span style="color: #000066;">join</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1900</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$year</span> <span style="color: #339933;">||</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$month</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$day</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;"># }}}</span>
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$ab</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">export</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">auth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">logout</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This is intended as a sample code for using the WWW::Facebook::API perl module (there are way too few working examples out there). Let me know if you need complementary explanations about anything.</p>
<p><strong><br />
The only thing I really need to figure out now is how to proceed if I ever wanted to distribute this code without giving away the application secret. There is a rather <a href="http://code.google.com/p/facebook-java-api/wiki/DesktopMode" target="_blank">good general explanation of the authentication process of a facebook desktop application</a>, but I couldn&#8217;t find a working sample code to get started with. If you do know how to do that, please share in the comments.<br />
</strong></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-4571688872511149";
/* 728x90, created 10/17/09 */
google_ad_slot = "0784069657";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><a href="http://www.sakana.fr/blog/2010/11/02/facebook-api-exporting-your-friends-birthdays-into-vcards-format/">Facebook API : Exporting your friends birthdays into vCards format</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sakana.fr/blog/2010/11/02/facebook-api-exporting-your-friends-birthdays-into-vcards-format/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Perl : Counting occurences of IP addresses in Apache logs</title>
		<link>http://www.sakana.fr/blog/2010/03/02/perl-counting-occurences-of-ip-addresses-in-apache-logs/</link>
		<comments>http://www.sakana.fr/blog/2010/03/02/perl-counting-occurences-of-ip-addresses-in-apache-logs/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 11:41:57 +0000</pubDate>
		<dc:creator>Stephane Kattoor</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[apache logs]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.sakana.fr/blog/?p=408</guid>
		<description><![CDATA[This Perl one-liner is intended to print the 10 most frequent client IP addresses in an Apache log file. It can easily be recycled to count anything, though. ?View Code TXT1 2 3 4 5 6 7 8 9 10 11 12 kattoo@roadrunner /files/toSave/home/kattoo/Downloads $ perl -ane '$c{$F[0]}++; END {print map {$_ . &#34;\t-&#62;\t&#34; . [...]<p><a href="http://www.sakana.fr/blog/2010/03/02/perl-counting-occurences-of-ip-addresses-in-apache-logs/">Perl : Counting occurences of IP addresses in Apache logs</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This Perl one-liner is intended to print the 10 most frequent client IP addresses in an Apache log file. It can easily be recycled to count anything, though.<br />
<span id="more-408"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p408code8'); return false;">View Code</a> TXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4088"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p408code8"><pre class="txt" style="font-family:monospace;">kattoo@roadrunner /files/toSave/home/kattoo/Downloads $ perl -ane '$c{$F[0]}++; END {print map {$_ . &quot;\t-&gt;\t&quot; . $c{$_} . &quot;\n&quot;} (sort {$c{$b} &lt;=&gt; $c{$a}} keys %c)[0..9]}' sakana.fr-28-02-2010.log 
XX.XX.XX.XXX	-&gt;	163
XX.XXX.XXX.XXX	-&gt;	150
XXX.XXX.XX.XX	-&gt;	136
XXX.XX.XXX.XXX	-&gt;	134
XX.XXX.XXX.XX	-&gt;	116
XX.XXX.XXX.XXX	-&gt;	110
XX.XX.XXX.XX	-&gt;	104
XX.XXX.XXX.XXX	-&gt;	90
XX.XXX.X.XXX	-&gt;	75
XXX.XXX.XX.XXX	-&gt;	72
kattoo@roadrunner /files/toSave/home/kattoo/Downloads $</pre></td></tr></table></div>

<p>Short explanation of the command line switches :</p>
<ul>
<li><strong>-a</strong> : turns on autosplit, the different fields will then be accessible in the <em>@F</em> variable</li>
<li><strong>-e</strong> : specifies the code to execute</li>
<li><strong>-n</strong>  : wraps that code into a loop for each text line of the file to process from the standard input or the files specified on the command line</li>
</ul>
<p>This is equivalent to <a href="http://blog.anotherhomepage.org/post/2010/03/01/Nombre-d-occurences-d-un-champ-dans-un-fichier" target="_blank">Nils&#8217; approach in awk</a> but you know, I&#8217;ve always been partial to Perl <img src='http://www.sakana.fr/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Feel free to suggest any improvement&#8230; I know there must be many !</p>
<p><strong>Suggested reading</strong></p>
<ul>
<li><a href="http://www.amazon.com/gp/product/0596000278?ie=UTF8&#038;tag=tecsak-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0596000278" target="_blank">Programming Perl (3rd Edition)</a><img src="http://www.assoc-amazon.com/e/ir?t=tecsak-20&#038;l=as2&#038;o=1&#038;a=0596000278" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> (on Amazon) : The reference guide for Perl programming, written by Perl Gods (Larry Wall, Tom Christiansen, John Orwant).</li>
<li><a href="http://articles.techrepublic.com.com/5100-10878_11-1044668.html" target="_blank">Use command-line Perl to make UNIX administration easier</a> (on techrepublic) : Short intro about perl 1-liners</li>
</ul>
<p><!--adsense--></p>
<p><a href="http://www.sakana.fr/blog/2010/03/02/perl-counting-occurences-of-ip-addresses-in-apache-logs/">Perl : Counting occurences of IP addresses in Apache logs</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sakana.fr/blog/2010/03/02/perl-counting-occurences-of-ip-addresses-in-apache-logs/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Perl+Twitter : Getting @mentions from command line</title>
		<link>http://www.sakana.fr/blog/2010/01/24/perltwitter-getting-mentions-from-command-line/</link>
		<comments>http://www.sakana.fr/blog/2010/01/24/perltwitter-getting-mentions-from-command-line/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 09:56:09 +0000</pubDate>
		<dc:creator>Stephane Kattoor</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[@mentions]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.sakana.fr/blog/?p=397</guid>
		<description><![CDATA[This code snippet demonstrates how easy it is to collect your twitter @mentions in Perl, coupled with curl for simplicity. In this script, we use the JSON Twitter API. Perl has a JSON module to make parsing or JSON streams a bliss. I also used formats for easy ?Download twitter-mentions.pl1 2 3 4 5 6 [...]<p><a href="http://www.sakana.fr/blog/2010/01/24/perltwitter-getting-mentions-from-command-line/">Perl+Twitter : Getting @mentions from command line</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This code snippet demonstrates how easy it is to collect your twitter @mentions in Perl, coupled with curl for simplicity.<br />
<span id="more-397"></span><br />
<!--adsense--></p>
<p>In this script, we use the JSON Twitter API. Perl has a JSON module to make parsing or JSON streams a bliss. I also used formats for easy</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.sakana.fr/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=397&amp;download=twitter-mentions.pl">twitter-mentions.pl</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39711"><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
</pre></td><td class="code" id="p397code11"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> JSON<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Encode<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$json</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSON<span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$json_stream</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/join.html"><span style="color: #000066;">join</span></a> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">,</span> <a href="http://perldoc.perl.org/functions/map.html"><span style="color: #000066;">map</span></a> <span style="color: #009900;">&#123;</span>decode<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">&lt;&gt;;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$mentions</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$json</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">decode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$json_stream</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$mention</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@$mentions</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$screen_name</span> <span style="color: #339933;">=</span> encode<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$mention</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>user<span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>screen_name<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$text</span> <span style="color: #339933;">=</span> encode<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$mention</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>text<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<a href="http://perldoc.perl.org/functions/format.html"><span style="color: #000066;">format</span></a> <span style="color: #339933;">=</span>
<span style="color: #339933;">@&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span>    <span style="color: #339933;">^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span>
<span style="color: #0000ff;">$screen_name</span><span style="color: #339933;">,</span>      <span style="color: #0000ff;">$text</span>
                   <span style="color: #339933;">^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span> <span style="color: #339933;">~~</span>
				   <span style="color: #0000ff;">$text</span>
<span style="color: #339933;">.</span>
	<a href="http://perldoc.perl.org/functions/write.html"><span style="color: #000066;">write</span></a><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You&#8217;ll have to run it as demonstrated below :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p397code12'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39712"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p397code12"><pre class="text" style="font-family:monospace;">kattoo@roadrunner /files/toSave/home/kattoo $ curl -sS -u YourLoginHere:YourPasswordHere http://twitter.com/statuses/mentions.json | twitter-mentions.pl 
divarvel           @killermouse0 mon /boot est pas dans une
                   partition à part, et pour une install en
                   chroot je ne sais pas quoi faire (un autre
                   /boot ?)
fenice             @killermouse0 merci, c'est sympa. Tu tourne
                   sous Gentoo ?
[...]
kattoo@roadrunner /files/toSave/home/kattoo $</pre></td></tr></table></div>

<p>That&#8217;s all ! Of course this piece of code could use a lot of improvements, but this is intended as a kickstart sample&#8230; The curl part could have been directly integrated into the Perl code, but I like to keep it simple.</p>
<p>Now off to integrate this in <a href="http://www.sakana.fr/blog/2009/10/11/conky-integrating-rtorrent-downloads-monitoring/" target="_blank">my Conky layout</a> <img src='http://www.sakana.fr/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><strong>And by the way, you&#8217;ll find my twitter account on the right, in the &#8220;Follow me&#8221; section. Feel free to add me for updates !</strong></p>
<h4>Worth reading</h4>
<ul>
<li><a href="http://www.sakana.fr/blog/2007/03/17/twitter-send-free-sms-messages/">Twitter : Send free SMS messages to your friends</a> : now you can do this from the command line</li>
<li><a href="http://www.sakana.fr/blog/2007/03/18/scripting-twitter-with-curl/">Scripting Twitter with cURL</a></li>
<li><a href="http://www.sakana.fr/blog/2007/03/18/scripting-twitter-with-perl-lwp/">Scripting Twitter with Perl + LWP</a> : a script in Perl doing the same thing (much simpler).</li>
<li><a href="http://www.sakana.fr/blog/2010/01/24/perltwitter-getting-mentions-from-command-line/">Perl+Twitter : Getting @mentions from command line</a></li>
</ul>
<p><!--adsense--></p>
<p><a href="http://www.sakana.fr/blog/2010/01/24/perltwitter-getting-mentions-from-command-line/">Perl+Twitter : Getting @mentions from command line</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sakana.fr/blog/2010/01/24/perltwitter-getting-mentions-from-command-line/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Perl : Using the Finance::Quote module to get your stock prices</title>
		<link>http://www.sakana.fr/blog/2009/12/30/perl-using-the-financequote-module-to-get-your-stock-prices/</link>
		<comments>http://www.sakana.fr/blog/2009/12/30/perl-using-the-financequote-module-to-get-your-stock-prices/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 15:02:25 +0000</pubDate>
		<dc:creator>Stephane Kattoor</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[conky]]></category>
		<category><![CDATA[Finance::Quote]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[stocks]]></category>

		<guid isPermaLink="false">http://www.sakana.fr/blog/?p=367</guid>
		<description><![CDATA[Finance::Quote is a Perl module which can be used to obtain stock information from various internet sources. I thought I&#8217;d rather share this code snippet as an example showing how easy it is to use, before I turn it into a bloatware with an SQL backend to compute average price per share and what not [...]<p><a href="http://www.sakana.fr/blog/2009/12/30/perl-using-the-financequote-module-to-get-your-stock-prices/">Perl : Using the Finance::Quote module to get your stock prices</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://finance-quote.sourceforge.net/" target="_blank">Finance::Quote</a> is a Perl module which can be used to obtain stock information from various internet sources. I thought I&#8217;d rather share this code snippet as an example showing how easy it is to use, before I turn it into a bloatware with an SQL backend to compute <a href="http://www.investorglossary.com/average-price-per-share.htm" target="_blank">average price per share</a> and what not <img src='http://www.sakana.fr/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>So here is a simple snippet demonstrating how to get the price of a stock :<br />
<span id="more-367"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.sakana.fr/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=367&amp;download=get-stocks.pl">get-stocks.pl</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36715"><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
34
35
36
</pre></td><td class="code" id="p367code15"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Finance<span style="color: #339933;">::</span><span style="color: #006600;">Quote</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$q</span> <span style="color: #339933;">=</span> Finance<span style="color: #339933;">::</span><span style="color: #006600;">Quote</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@tickers</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;CS.PA&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;DEXB.PA&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;AF.PA&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;VIE.PA&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;KEYYO.PA&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$s</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;yahoo_europe&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@tickers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$stocks</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$k</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/each.html"><span style="color: #000066;">each</span></a> <span style="color: #0000ff;">%$s</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$stock</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$label</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$stock</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$label</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a> <span style="color: #0000ff;">$;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$k</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$stocks</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$stock</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$label</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$v</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@data</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@tickers</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #0000ff;">$stocks</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>success<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@data</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> name <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">,</span> price <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;N/A&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@data</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$stocks</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@sorted</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/sort.html"><span style="color: #000066;">sort</span></a> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$a</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>name<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">cmp</span> <span style="color: #0000ff;">$b</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>name<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #0000ff;">@data</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">@data</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/undef.html"><span style="color: #000066;">undef</span></a><span style="color: #339933;">;</span>
&nbsp;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <a href="http://perldoc.perl.org/functions/sprintf.html"><span style="color: #000066;">sprintf</span></a> <span style="color: #ff0000;">&quot;% -20s %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;STOCK&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;PRICE&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@sorted</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <a href="http://perldoc.perl.org/functions/sprintf.html"><span style="color: #000066;">sprintf</span></a> <span style="color: #ff0000;">&quot;% -20s % 7.2f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>name<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>price<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The execution will provide something like that :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p367code16'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36716"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p367code16"><pre class="shell" style="font-family:monospace;">kattoo@roadrunner ~/bin $ ./get-stocks.pl 
STOCK                PRICE
AIR FRANCE - KLM       11.35
AXA                    16.64
DEXIA                   4.87
KEYYO                   3.30
VEOLIA ENVIRONN.       22.70
kattoo@roadrunner ~/bin $</pre></td></tr></table></div>

<p>That&#8217;s pretty simple so I won&#8217;t go into more details (feel free to ask if you need clarifications).</p>
<p>I&#8217;ve already added it into my <a href="http://www.sakana.fr/blog/2009/10/11/conky-integrating-rtorrent-downloads-monitoring/" target="_blank">conky layout</a> with an execpi directive, and it works like a charm <img src='http://www.sakana.fr/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a href="http://www.sakana.fr/blog/2009/12/30/perl-using-the-financequote-module-to-get-your-stock-prices/">Perl : Using the Finance::Quote module to get your stock prices</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sakana.fr/blog/2009/12/30/perl-using-the-financequote-module-to-get-your-stock-prices/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>D-Bus introduction in Perl</title>
		<link>http://www.sakana.fr/blog/2009/03/08/linux-d-bus-intro-in-perl/</link>
		<comments>http://www.sakana.fr/blog/2009/03/08/linux-d-bus-intro-in-perl/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 21:46:36 +0000</pubDate>
		<dc:creator>Stephane Kattoor</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[d-bus]]></category>
		<category><![CDATA[intro]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[pidgin]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.sakana.fr/blog/?p=214</guid>
		<description><![CDATA[As stated in Wikipedia : D-Bus (Desktop Bus) is a simple inter-process communication (IPC) system for software applications to communicate with one another. This post provides a simple code snippet in Perl to help you getting started with D-Bus programming. D-Bus is used by many applications to provide users with a more tightly integrated desktop [...]<p><a href="http://www.sakana.fr/blog/2009/03/08/linux-d-bus-intro-in-perl/">D-Bus introduction in Perl</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>As stated in <a title="D-Bus on Wikipedia" href="http://en.wikipedia.org/wiki/D-Bus" target="_blank">Wikipedia</a> :</p>
<blockquote><p>D-Bus (Desktop Bus) is a simple inter-process communication (IPC) system for software applications to communicate with one another.</p></blockquote>
<p>This post provides a simple code snippet in Perl to help you getting started with D-Bus programming. <span id="more-214"></span></p>
<p>D-Bus is used by many applications to provide users with a more tightly integrated desktop environment. Basically, an application can use D-Bus to provide services as well as to notify other application when a specific event occurs.</p>
<p>For example, the instant messaging client Pidgin will send a signal on D-Bus when a buddy on the contact list will connect. An application listening for this signal on the D-Bus pick it up (think <em>inter-process messages</em>) and then use D-Bus to ask extra informations to Pidgin about this buddy (think <em>remote procedure call</em>).</p>
<p>As I wanted to experiment with D-Bus, I&#8217;ve put this little example in practice. The code is pretty much self explanatory. It is coded in Perl as this is the language I use the most. Besides there are already plenty of examples of D-Bus programming in Python, but not so many in Perl.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p214code18'); return false;">View Code</a> PERL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21418"><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
</pre></td><td class="code" id="p214code18"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> Net<span style="color: #339933;">::</span><span style="color: #006600;">DBus</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Net<span style="color: #339933;">::</span><span style="color: #006600;">DBus</span><span style="color: #339933;">::</span><span style="color: #006600;">Reactor</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># There is the system bus and the session bus. Here we are</span>
<span style="color: #666666; font-style: italic;"># interested in the session bus</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$bus</span> <span style="color: #339933;">=</span> Net<span style="color: #339933;">::</span><span style="color: #006600;">DBus</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">session</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># we connect the services Pidgin offers through D-Bus</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$purple</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$bus</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get_service</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'im.pidgin.purple.PurpleService'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$object</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$purple</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get_object</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'/im/pidgin/purple/PurpleObject'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'im.pidgin.purple.PurpleInterface'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># we register a signal handler for when a connection occurs</span>
<span style="color: #0000ff;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect_to_signal</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'BuddySignedOn'</span><span style="color: #339933;">,</span>
    <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$buddyId</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a><span style="color: #339933;">;</span>
        <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;BuddySignedOn:&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">PurpleBuddyGetAlias</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$buddyId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># and we start the main loop where the events are processed</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$reactor</span> <span style="color: #339933;">=</span> Net<span style="color: #339933;">::</span><span style="color: #006600;">DBus</span><span style="color: #339933;">::</span><span style="color: #006600;">Reactor</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">main</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$reactor</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://perldoc.perl.org/functions/exit.html"><span style="color: #000066;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>So all in all it makes it easy to offer the user an integrated environment thanks to D-Bus.</p>
<p>Imagine that, every time a new song is played in your music player, a signal is sent on the bus and your instant messaging client picks it up to display it in your status ? Easy to do with D-Bus ! And of course there are endless possibilities to make applications work together !</p>
<p><!--adsense--></p>
<p><a href="http://www.sakana.fr/blog/2009/03/08/linux-d-bus-intro-in-perl/">D-Bus introduction in Perl</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sakana.fr/blog/2009/03/08/linux-d-bus-intro-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL : binary log files</title>
		<link>http://www.sakana.fr/blog/2008/04/07/mysql-binary-log-files/</link>
		<comments>http://www.sakana.fr/blog/2008/04/07/mysql-binary-log-files/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 20:53:42 +0000</pubDate>
		<dc:creator>Stephane Kattoor</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[binary logs]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://www.sakana.fr/blog/?p=144</guid>
		<description><![CDATA[MySQL uses the so called binary log files to implement master/slaves replication. You can set the expire_logs_days variable in your my.cnf file, which will set the number of days MySQL will keep those binary log files. This is the longest time a MySQL replication slave can lag behind the master. If for a reason the [...]<p><a href="http://www.sakana.fr/blog/2008/04/07/mysql-binary-log-files/">MySQL : binary log files</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.sakana.fr/blog/wp-content/uploads/2008/03/logo_mysql_sun.gif" alt="MySQL" align="left" border="2" />MySQL uses the so called binary log files to implement master/slaves replication.</p>
<p><span id="more-144"></span></p>
<p>You can set the expire_logs_days variable in your my.cnf file, which will set the number of days MySQL will keep those binary log files.</p>
<p>This is the longest time a MySQL replication slave can lag behind the master. If for a reason the slave is not able to replicate for more than this duration, then it won&#8217;t be able to catch back (you will have to get back data from the server one way or another)</p>
<p>To clean the binary log files you can use the &#8220;<a href="http://dev.mysql.com/doc/refman/5.1/en/purge-master-logs.html" title="PURGE MASTER LOGS" target="_blank">PURGE MASTER LOGS</a>&#8221;  SQL command which can delete binary logs before a specified date or till a specified binary log file.</p>
<p>To see the binary log files on the server, you can use the &#8220;<a href="http://dev.mysql.com/doc/refman/5.1/en/show-binary-logs.html" title="SHOW BINARY LOGS" target="_blank">SHOW BINARY LOGS</a>&#8221; SQL command.</p>
<p>At last, to know up to which file you could delete the binary log files, you can run the &#8220;<a href="http://dev.mysql.com/doc/refman/5.1/en/show-slave-status.html" title="SHOW SLAVE STATUS" target="_blank">SHOW SLAVE STATUS</a>&#8221; on each replication slave to see which binary log file they are using, and delete up to the oldest of them.</p>
<p><!--adsense--></p>
<p><a href="http://www.sakana.fr/blog/2008/04/07/mysql-binary-log-files/">MySQL : binary log files</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sakana.fr/blog/2008/04/07/mysql-binary-log-files/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Perl : Convert time from Epoch to local time</title>
		<link>http://www.sakana.fr/blog/2008/03/06/perl-convert-time-from-epoch-to-local-time/</link>
		<comments>http://www.sakana.fr/blog/2008/03/06/perl-convert-time-from-epoch-to-local-time/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 20:07:25 +0000</pubDate>
		<dc:creator>Stephane Kattoor</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[epoch]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[localtime]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.sakana.fr/blog/2008/03/06/perl-convert-time-from-epoch-to-local-time/</guid>
		<description><![CDATA[This little Perl one-liner can get handy when you need to translate &#8220;time in seconds since the Epoch&#8221; (for example in logs) to local time : % perl -e &#039;print scalar(localtime(1202484725)), &#34;\n&#34;;&#039; Fri Feb&#160;&#160;8 16:32:05 2008 % This was pretty useful today when browsing through Nagios event logs, where times are given in seconds from [...]<p><a href="http://www.sakana.fr/blog/2008/03/06/perl-convert-time-from-epoch-to-local-time/">Perl : Convert time from Epoch to local time</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.sakana.fr/blog/wp-content/uploads/2008/03/watch.jpg" alt="watch" align="bottom" /></p>
<p>This little Perl one-liner can get handy when you need to translate &#8220;time  in seconds since the Epoch&#8221; (for example in logs) to local time :<br />
<pre><code>% perl -e &#039;print scalar(localtime(1202484725)), &quot;\n&quot;;&#039;
Fri Feb&nbsp;&nbsp;8 16:32:05 2008
%</code></pre></p>
<p>This was pretty useful today when browsing through Nagios event logs, where times are given in seconds from the Epoch.</p>
<p>By the way, the Epoch is defined as 00:00 UTC on January, 1st, 1970.</p>
<p><!--adsense--></p>
<p><a href="http://www.sakana.fr/blog/2008/03/06/perl-convert-time-from-epoch-to-local-time/">Perl : Convert time from Epoch to local time</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sakana.fr/blog/2008/03/06/perl-convert-time-from-epoch-to-local-time/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Perl : A module to play with a GSM mobile</title>
		<link>http://www.sakana.fr/blog/2007/12/26/perl-a-module-to-play-with-a-gsm-mobile/</link>
		<comments>http://www.sakana.fr/blog/2007/12/26/perl-a-module-to-play-with-a-gsm-mobile/#comments</comments>
		<pubDate>Wed, 26 Dec 2007 20:10:21 +0000</pubDate>
		<dc:creator>Stephane Kattoor</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[cell phone]]></category>
		<category><![CDATA[gsm]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[phonebook]]></category>
		<category><![CDATA[sms]]></category>

		<guid isPermaLink="false">http://www.sakana.fr/blog/2007/12/26/perl-a-module-to-play-with-a-gsm-mobile/</guid>
		<description><![CDATA[As you might have read in my previous post about accessing your cell phone with the AT-commands under Linux. If not, you might want to start there for a little context. I finally wrote and released on CPAN a Perl module which will help to automate cell phone operations such as saving/restoring the phonebook or [...]<p><a href="http://www.sakana.fr/blog/2007/12/26/perl-a-module-to-play-with-a-gsm-mobile/">Perl : A module to play with a GSM mobile</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>As you might have read in my previous post about <a href="http://www.sakana.fr/blog/2007/12/23/linux-gsm-how-to-access-your-cell-phone-innards-with-linux/" title="Accessing a GSM with AT-commands" target="_blank">accessing your cell phone with the AT-commands under Linux.</a></p>
<p>If not, you might want to start there for a little context.</p>
<p>I finally wrote and released on <a href="http://www.cpan.org" title="CPAN - Perl modules repository" target="_blank">CPAN</a> a Perl module  which will help to automate cell phone operations such as saving/restoring the phonebook or sending an SMS.</p>
<p>Examples are included in the documentation. I believe I made it easy to use, but let me know if I&#8217;m wrong <img src='http://www.sakana.fr/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  .</p>
<p>Features will be added on demand (if possible of course <img src='http://www.sakana.fr/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ).</p>
<p>The module is <a href="http://search.cpan.org/perldoc?Device::Modem::GSM" title="Device::Modem::GSM" target="_blank">Device::Modem::GSM</a>.</p>
<p><a href="http://www.sakana.fr/blog/2007/12/26/perl-a-module-to-play-with-a-gsm-mobile/">Perl : A module to play with a GSM mobile</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sakana.fr/blog/2007/12/26/perl-a-module-to-play-with-a-gsm-mobile/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Linux + GSM : How to access your cell phone innards with Linux</title>
		<link>http://www.sakana.fr/blog/2007/12/23/linux-gsm-how-to-access-your-cell-phone-innards-with-linux/</link>
		<comments>http://www.sakana.fr/blog/2007/12/23/linux-gsm-how-to-access-your-cell-phone-innards-with-linux/#comments</comments>
		<pubDate>Sun, 23 Dec 2007 16:25:04 +0000</pubDate>
		<dc:creator>Stephane Kattoor</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Systems]]></category>
		<category><![CDATA[AT-commands]]></category>
		<category><![CDATA[cell phone]]></category>
		<category><![CDATA[cu]]></category>
		<category><![CDATA[gsm]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[phonebook]]></category>
		<category><![CDATA[rs232]]></category>
		<category><![CDATA[serial port]]></category>
		<category><![CDATA[SIM card]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[uart]]></category>

		<guid isPermaLink="false">http://www.sakana.fr/blog/2007/12/23/linux-gsm-how-to-access-your-cell-phone-innards-with-linux/</guid>
		<description><![CDATA[This article explores your options to access your GSM cell phone from a linux system, and manipulate SMS and phonebook entries. Doesn&#8217;t provide hints about how to unlock a GSM cell phone though Existing tools As usual it started with what seemed to be a simple need : I wanted to backup the contacts SIM [...]<p><a href="http://www.sakana.fr/blog/2007/12/23/linux-gsm-how-to-access-your-cell-phone-innards-with-linux/">Linux + GSM : How to access your cell phone innards with Linux</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This article explores your options to access your GSM cell phone from a linux system, and manipulate SMS and phonebook entries.</p>
<p>Doesn&#8217;t provide hints about how to unlock a  GSM cell phone though <img src='http://www.sakana.fr/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><span id="more-124"></span></p>
<h3>Existing tools</h3>
<p>As usual it started with what seemed to be a simple need : I wanted to backup the contacts SIM card&#8217;s memory. I installed and tried various pieces of software with various but consistently disappointing results :</p>
<ul>
<li>kmobiletools : neat GUI, able to load the phonebook, but no option to export it to a file or restore it (but it works great if you want to send SMS from your computer with your mobile attached)</li>
<li>kandy : nice interface, and is supposed to be able to sync your KDE AddressBook &#8230; but as far as my test went, it was not able to connect to my cell phone (maybe it will work with yours)</li>
<li>xgsm / gsmlib : this one&#8217;s GUI is ugly, but at least it was possible to connect to the cell phone and save the phonebook to a file&#8230; but unfortunately it failed to restore it !!!</li>
<li>KitchenSync was supposed to be a kind of universal sync tool, but as far as I&#8217;m concerned I didn&#8217;t manage to get anything out of it</li>
</ul>
<p>You might first give a try to those tools and the others, they didn&#8217;t work for me but it doesn&#8217;t mean it won&#8217;t work for you !</p>
<h3>DIY approach</h3>
<h4>Connecting the data cable</h4>
<p>First let&#8217;s plug that data cable you bought for your cell phone from any mobile phone shop or from ebay.<br />
Here&#8217;s what shows up with a <tt>dmesg</tt> :<br />
<pre><code>spaghetti:~/$ dmesg
[492737.436000] usb 2-2: new full speed USB device using uhci_hcd and address 5
[492737.604000] usb 2-2: configuration #1 chosen from 1 choice
[492737.604000] cp2101 2-2:1.0: cp2101 converter detected
[492737.720000] usb 2-2: reset full speed USB device using uhci_hcd and address 5
[492737.868000] usb 2-2: cp2101 converter now attached to ttyUSB0
spaghetti:~/$</code></pre></p>
<p>Looking up in google to know what is a CP2101 &#8230; This &#8220;USB data cable&#8221; is just a USB attached Serial Adapter (RS232 interface), which you can use like any other serial port under linux and which is now attached to /dev/ttyUSB0.</p>
<h4>Connecting to the cell phone over this serial port</h4>
<p>What then came to my mind is to use a terminal emulator capable of talking over a serial line. There are many such tool (<tt>minicom</tt>, <tt>kermit</tt>, <tt>hyperterminal</tt> &#8230; pick your favorite one). I tend to use <tt>cu</tt> for this purpose.<br />
<pre><code>spaghetti% cu -h -s 38400 -l /dev/ttyUSB0
Connected.</code></pre><br />
Hmm that was easy &#8230; For the parameters, here is the explanation :</p>
<ul>
<li>-h : turns on local echo (for you to see what you type in)</li>
<li>-s : chooses the speed</li>
<li>-l : chooses the tty matching the serial port you want to use</li>
</ul>
<h4>Trying a few commands</h4>
<p>Some more googling and it turns out that one talks to his GSM cell phone as one would talk to those old RTC modems, using &#8220;AT-commands&#8221;. Those AT-commands are fairly standardized in the GSM specifications.<br />
For example, here is how to seek an entry from the phonebook (&#8220;<strong>PB</strong>&#8220;) on the SIM card (the &#8220;<strong>SM</strong>&#8221; storage). Note that the ^M are the <tt>enter</tt> I type in :<br />
<pre><code>spaghetti% cu -h -s 38400 -l /dev/ttyUSB0
Connected.
AT+CPBS=&quot;SM&quot;^M
OK
AT+CPBR=13^M
+CPBR: 13,&quot;33123456789&quot;,145,&quot;Some Dude&quot;
OK</code></pre></p>
<p>We first selected the phonebook storage &#8220;<strong>SM</strong>&#8221; (the SIM card) and then fetched the 13th record out of it. The <strong>145</strong> which came along means the phone number is in international form (you have to add a &#8220;+&#8221; ahead of it when dialing).<br />
Let&#8217;s write an entry :<br />
<pre><code>AT+CPBW=61,&quot;1234&quot;,129,&quot;Name Dude&quot;^M
OK
AT+CPBR=61^M
+CPBR: 61,&quot;1234&quot;,129,&quot;Name Dude&quot;</code></pre><br />
First we wrote the entry with the <tt>AT+CPBW</tt> command then read it back with <tt>AT+CPBR</tt>. The <strong>129</strong> means the phone number is not in its international form.</p>
<p>Now we could send an SMS :<br />
<pre><code>AT+CMGF=1^M
OK
AT+CMGS=&quot;+33123456&quot;^M
&amp;gt; Did you get that ?^Z
+CMGS: 0
OK</code></pre></p>
<p>First we specify that the SMS will be in &#8220;text format&#8221; with the <tt>AT+CMGF</tt> command. Then we send the SMS with the <tt>AT+CMGS</tt> command. First the number, then the text which is terminated with a ^Z.</p>
<h4>Scripting, anyone ?</h4>
<p>Of course, you might want to automate this all. You might want to backup / restore your SIM card, send an SMS from a script and so on &#8230;<br />
For such purposes, there is a Perl module <a href="http://search.cpan.org/dist/Device-Modem/docs/Device-Modem.pod" title="Device::Modem">Device::Modem</a> which will let you send AT-commands and get results very simply. And I am currently writing the Device::Modem::GSM module which will make it easy to interact with a GSM mobile phone.</p>
<h3>References</h3>
<p>This post barely scratches the surface of what you can do by using AT-commands with your mobile. You can read about all the other commands in the GSM reference on AT-commands, which you&#8217;ll find on the internet with a <a href="http://www.google.com/search?hl=en&amp;q=07.07+GSM+filetype%3Apdf+%22TS+100+916%22&amp;btnG=Search" title="Find the GSM standardized AT-commands">wisely built search query</a>.</p>
<p>Developers&#8217; home runs a nice <a href="http://www.developershome.com/sms/" title="Developers'home tutorial on SMSes" target="_blank">technical tutorial about SMSes</a> too.</p>
<h3>Question to the readers</h3>
<p>As I said, I am currently writing a Perl module to simplify GSM automation. I had in mind phonebook operations and SMS sending &#8230; What other features would you like to see implemented ?</p>
<p>Your ideas in the comments !</p>
<p><!--adsense--></p>
<p><a href="http://www.sakana.fr/blog/2007/12/23/linux-gsm-how-to-access-your-cell-phone-innards-with-linux/">Linux + GSM : How to access your cell phone innards with Linux</a> is a post from: <a href="http://www.sakana.fr/blog">Tech@Sakana - A sysadmin's blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sakana.fr/blog/2007/12/23/linux-gsm-how-to-access-your-cell-phone-innards-with-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

