<?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> &#187; UNIX Scripting</title>
	<atom:link href="http://raffy.ch/blog/category/unix-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://raffy.ch/blog</link>
	<description>Log visualization and log management as seen by Raffael Marty</description>
	<lastBuildDate>Wed, 28 Jul 2010 02:04:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Database Query Analysis</title>
		<link>http://raffy.ch/blog/2007/10/15/database-query-analysis/</link>
		<comments>http://raffy.ch/blog/2007/10/15/database-query-analysis/#comments</comments>
		<pubDate>Tue, 16 Oct 2007 02:54:59 +0000</pubDate>
		<dc:creator>Raffael Marty</dc:creator>
				<category><![CDATA[Log Analysis]]></category>
		<category><![CDATA[UNIX Scripting]]></category>
		<category><![CDATA[Visualization]]></category>

		<guid isPermaLink="false">http://raffy.ch/blog/2007/10/15/database-query-analysis/</guid>
		<description><![CDATA[I was playing with database audit logs for a bit to try and visualize some aspects of them. While doing so, I came across a pretty interesting problem. The audit logs contain entries that indicate what exact SQL query was executed. Now, I am not interested in the entire query, but I need to know [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://raffy.ch/blog/wp-content/uploads/2007/10/icon.thumbnail.jpg" alt="icon.jpg" style="margin: 0pt 10px 10px 0pt; float: left" border="0" />I was playing with database audit logs for a bit to try and visualize some aspects of them. While doing so, I came across a pretty interesting problem. The audit logs contain entries that indicate what exact SQL query was executed. Now, I am not interested in the entire query, but I need to know which tables were touched. I was trying to build some regular expressions to extract that information from the query, but I gave up pretty quickly. It&#8217;s just too complicated for a regex. I was wondering whether there is a way to take a SQL query, for example:</p>
<p><code>select * from a.table1 a, b.tabl2 b join c.table3 on b.id1=c.id2 where a.foo='bar'</code></p>
<p>and extract all the table names: a.table1, b.table2, c.table3. Are there tools to do that? Remember, I don&#8217;t have the database with these tables. I only have a log from some database. The script should support all the SQL perks like joins, nested selects, etc. Anyone have a good way to do this?</p>
]]></content:encoded>
			<wfw:commentRss>http://raffy.ch/blog/2007/10/15/database-query-analysis/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Parsing XML on the Command Line</title>
		<link>http://raffy.ch/blog/2007/07/25/parsing-xml-on-the-command-line/</link>
		<comments>http://raffy.ch/blog/2007/07/25/parsing-xml-on-the-command-line/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 16:24:04 +0000</pubDate>
		<dc:creator>Raffael Marty</dc:creator>
				<category><![CDATA[UNIX Scripting]]></category>

		<guid isPermaLink="false">http://raffy.ch/blog/2007/07/25/parsing-xml-on-the-command-line/</guid>
		<description><![CDATA[I haven&#8217;t written about UNIX scripting in a while. It was yesterday in the afternoon that our QA guy came over and asked me some questions about VI. Among his problems was the &#8220;parsing of an XML&#8221; file. He wanted to extract elements from specific branches of an XML structure. I told him that VI [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t written about UNIX scripting in a while. It was yesterday in the afternoon that our QA guy came over and asked me some questions about VI. Among his problems was the &#8220;parsing of an XML&#8221; file. He wanted to extract elements from specific branches of an XML structure. I told him that VI was not XML aware. It treats XMLs just like any other text file; line by line. He was not happy with my answer and kept bugging me. Then he said: &#8220;You should write a tool called XMLgrep&#8221;. And that was it. I was pretty sure that someone had written a tool that would do exactly that.</p>
<p>After 30 seconds on google, I found it: <a href="http://xmlstar.sourceforge.net">XMLStarlet</a>. It took me about 30 minutes to get the hang of the tool, but it is really cool. It takes <a href="http://www.w3schools.com/xpath/">XPATH</a> queries as an input. My knowledge of XPATH goes back to my <a href="http://thor.cryptojail.net">thesis</a> and is a bit rusty, but I finally got it right. Here is an example of how to apply an XPATH query to an XML file:</p>
<p><code>xmlstarlet sel -t -c "/archive/ActiveList[@name='Public Webmail']/description" JSOX_ActiveLists.xml<br />
</code></p>
<p>another one:</p>
<p><code>xmlstarlet sel -t -m "/archive/ActiveList" -v "concat (@name,'<br />
')" JSOX_ActiveLists.xm<br />
</code></p>
<p>Yes, there is a newline in this command. However, it didn&#8217;t really work for me. What I wanted to do is separating the different outputs with a newline, but for some reason this didn&#8217;t work. I tried all kinds of things, but no luck. Oh well.</p>
<p>Here is another link that might be useful. It&#8217;s a nice <a href="http://www.ibm.com/developerworks/library/x-starlet.html">tutorial</a> on XMLStarlet.</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/xml" rel="tag">xml</a>, <a href="http://technorati.com/tag/parsing" rel="tag">parsing</a>, <a href="http://technorati.com/tag/command+line" rel="tag">command line</a>, <a href="http://technorati.com/tag/xpath" rel="tag">xpath</a>, <a href="http://technorati.com/tag/xmlstarlet" rel="tag">xmlstarlet</a></p>
]]></content:encoded>
			<wfw:commentRss>http://raffy.ch/blog/2007/07/25/parsing-xml-on-the-command-line/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Not so Random Numbers</title>
		<link>http://raffy.ch/blog/2007/03/20/not-so-random-numbers/</link>
		<comments>http://raffy.ch/blog/2007/03/20/not-so-random-numbers/#comments</comments>
		<pubDate>Wed, 21 Mar 2007 02:05:18 +0000</pubDate>
		<dc:creator>Raffael Marty</dc:creator>
				<category><![CDATA[UNIX Scripting]]></category>

		<guid isPermaLink="false">http://raffy.ch/blog/2007/03/20/not-so-random-numbers/</guid>
		<description><![CDATA[In cryptography or science in general, you often need perfect random numbers. Well, up to today, that was my need as well. However, today I was trying to generate numbers that are not too random, but have a certain bias. I think it&#8217;s kind of ironic. Googling for a solution is almost impossible. Every link [...]]]></description>
			<content:encoded><![CDATA[<p>In cryptography or science in general, you often need perfect random numbers. Well, up to today, that was my need as well. However, today I was trying to generate numbers that are not too random, but have a certain bias. I think it&#8217;s kind of ironic. Googling for a solution is almost impossible. Every link shows a perfect random number generator <img src='http://raffy.ch/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I don&#8217;t care what the bias is in the numbers that are generated. Actually, the bias can be pretty high. Anyone have a method to do this in Perl?</p>
<p>Can you do something like int(rand($upperLimit*1000)) % 1000 ??? Basically changing the interval from where the random number is taken and then shrinking it again?</p>
]]></content:encoded>
			<wfw:commentRss>http://raffy.ch/blog/2007/03/20/not-so-random-numbers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Geo Lookup on the Command Line</title>
		<link>http://raffy.ch/blog/2007/02/24/geo-lookup-on-the-command-line/</link>
		<comments>http://raffy.ch/blog/2007/02/24/geo-lookup-on-the-command-line/#comments</comments>
		<pubDate>Sun, 25 Feb 2007 01:56:10 +0000</pubDate>
		<dc:creator>Raffael Marty</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[UNIX Scripting]]></category>

		<guid isPermaLink="false">http://raffy.ch/blog/2007/02/24/geo-lookup-on-the-command-line/</guid>
		<description><![CDATA[By now you should know that I really like command line tools which operate well when applied to data through a pipe. I have posted quite a few tips already to do data manipulation on the command line. Today I wanted a quick way to lookup IP address locations and add them to a log [...]]]></description>
			<content:encoded><![CDATA[<p>By now you should know that I really like command line tools which operate well when applied to data through a pipe. I have posted quite a few tips already to do data manipulation on the command line. Today I wanted a quick way to lookup IP address locations and add them to a log file. After investigating a few free databases, I came accross <strong>Geo::IPFree</strong>, a Perl library which does the trick. So here is how you add the country code. First, this is the format of my log entries:</p>
<p><code>10/13/2005 20:25:54.032145,195.141.211.178,195.131.61.44,2071,135</code></p>
<p>I want to get the country of the source address (first IP in the log). Here we go:</p>
<p><code> cat pflog.csv | perl -M'Geo::IPfree' -na -F/,/ -e '($country,$country_name)=Geo::IPfree::LookUp($F[1]);chomp; print "$_,$country_name\n"'</code></p>
<p>And here the output:</p>
<p><code>10/13/2005 20:24:33.494358,62.245.243.139,212.254.111.99,,echo request,Europe</code></p>
<p>Very simple!</p>
]]></content:encoded>
			<wfw:commentRss>http://raffy.ch/blog/2007/02/24/geo-lookup-on-the-command-line/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Command Line DNS Lookup</title>
		<link>http://raffy.ch/blog/2006/04/26/command-line-dns-lookup/</link>
		<comments>http://raffy.ch/blog/2006/04/26/command-line-dns-lookup/#comments</comments>
		<pubDate>Thu, 27 Apr 2006 04:09:02 +0000</pubDate>
		<dc:creator>Raffael Marty</dc:creator>
				<category><![CDATA[UNIX Scripting]]></category>

		<guid isPermaLink="false">http://raffy.ch/blog/?p=49</guid>
		<description><![CDATA[Something I ran into a couple of times this week is how to do an easy dns lookup on the command line:
cat data &#124; perl -M'Socket' -na -F/,/ -e '$dns=gethostbyaddr(inet_aton($F[0]),AF_INET)&#124;&#124;$F[0]; print "$dns,$F[1],$F[2]\n"'
The code assumes that you have an IP address in the first column. It uses -F/,/ to split the input into arrays, does a [...]]]></description>
			<content:encoded><![CDATA[<p>Something I ran into a couple of times this week is how to do an easy dns lookup on the command line:</p>
<p><code>cat data | perl -M'Socket' -na -F/,/ -e '$dns=gethostbyaddr(inet_aton($F[0]),AF_INET)||$F[0]; print "$dns,$F[1],$F[2]\n"'</code></p>
<p>The code assumes that you have an IP address in the first column. It uses -F/,/ to split the input into arrays, does a DNS lookup on the first column and returns either the dns name or if that was not found, it returns the original IP address.</p>
]]></content:encoded>
			<wfw:commentRss>http://raffy.ch/blog/2006/04/26/command-line-dns-lookup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wireless Access &#8211; Linux</title>
		<link>http://raffy.ch/blog/2006/01/16/wireless-access-linux/</link>
		<comments>http://raffy.ch/blog/2006/01/16/wireless-access-linux/#comments</comments>
		<pubDate>Mon, 16 Jan 2006 23:40:57 +0000</pubDate>
		<dc:creator>Raffael Marty</dc:creator>
				<category><![CDATA[UNIX Scripting]]></category>

		<guid isPermaLink="false">http://raffy.ch/blog/?p=24</guid>
		<description><![CDATA[Sitting down at a cafe around the corner from where I live, I realize that some of the scripts I wrote a while back might actually benefit others too. This one is to connect to the first available access point:
#!/bin/bash
iwlist ath0 s > /tmp/$$
ap=`cat /tmp/$$ &#124; grep "Encryption key:off" -B 5 &#124; head -1 &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>Sitting down at a cafe around the corner from where I live, I realize that some of the scripts I wrote a while back might actually benefit others too. This one is to connect to the first available access point:</p>
<p><code>#!/bin/bash</p>
<p>iwlist ath0 s > /tmp/$$</p>
<p>ap=`cat /tmp/$$ | grep "Encryption key:off" -B 5 | head -1 | sed -e 's/Cell.*Address: \(.*\)/\1/g'`<br />
essid=`cat /tmp/$$ | grep "Encryption key:off" -B 4 | head -1 | sed -e 's/ESSID:"\(.*\)"/\1/g'`<br />
essid=`echo $essid | sed -e 's/ //g'`</p>
<p>echo Tryping AP:$ap / SSID:$essid</p>
<p>iwconfig ath0 ap $ap<br />
iwconfig ath0 essid $essid<br />
iwconfig ath0 nick test<br />
killall -9 dhclient<br />
dhclient ath0<br />
</code></p>
<p>Not sure whether there would be a simpler solution natively supported by linux&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://raffy.ch/blog/2006/01/16/wireless-access-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
