<?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>mishmashmoo</title>
	<atom:link href="http://mishmashmoo.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://mishmashmoo.com/blog</link>
	<description>the technical blog of sameh abdelhamid</description>
	<lastBuildDate>Wed, 04 Aug 2010 00:31:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
<link>http://mishmashmoo.com/blog</link>
<url>http://mishmashmoo.com/blog/wp-content/mbp-favicon/transparent.ico</url>
<title>mishmashmoo</title>
</image>
		<item>
		<title>mysql gui database management</title>
		<link>http://mishmashmoo.com/blog/?p=136</link>
		<comments>http://mishmashmoo.com/blog/?p=136#comments</comments>
		<pubDate>Wed, 04 Aug 2010 00:31:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=136</guid>
		<description><![CDATA[I very rarely blog about an application, however sometimes there is an app or two that make my life and job a lot easier to manager. I use a lot of mysql databases, and managing them is something I like to, lets say&#8230;not do.
I simply don&#8217;t like navigating through databases and tables from the mysql [...]]]></description>
			<content:encoded><![CDATA[<p>I very rarely blog about an application, however sometimes there is an app or two that make my life and job a lot easier to manager. I use a lot of mysql databases, and managing them is something I like to, lets say&#8230;not do.<br />
I simply don&#8217;t like navigating through databases and tables from the mysql command line editor, and I really hate the PHP gui tool that it comes with&#8230;its just so cumbersome. I&#8217;ve been using navicat of late, but I hate the idea that I have to pay for it. I mean lets face it, why the heck would you want to pay for a tool that manages an open-source application! Its irony at its greatest. So in my early morning googling, I stumbled across a diamond among the db management tools.<br />
<span id="more-136"></span><br />
This little gem is called HeidiSQL. They are located <a href="http://www.heidisql.com/download.php">here</a>, although you can download the current version (at the time of writing this article) from <a href="http://mishmashmoo.com/downloads/HeidiSQL_5.1_Setup.exe">here</a>.<br />
Its basically a full GUI management tool of your mysql database, with a whole bunch of features. I wont go into the features, but check it out yourself. </p>
<p>Props to HeidiSQL and MySQl. </p>
<p>Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=136</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>oracle reporting through ruby</title>
		<link>http://mishmashmoo.com/blog/?p=124</link>
		<comments>http://mishmashmoo.com/blog/?p=124#comments</comments>
		<pubDate>Tue, 03 Aug 2010 06:15:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=124</guid>
		<description><![CDATA[As the cobwebs fill up on my blog just in time for spring, I thought it may best to clean it up and put some fresh stuff&#8230;So reporting is a kind of a big deal at these big corporations. Seems like there is always someone higher in the food chain who wants a spreadsheet to [...]]]></description>
			<content:encoded><![CDATA[<p>As the cobwebs fill up on my blog just in time for spring, I thought it may best to clean it up and put some fresh stuff&#8230;So reporting is a kind of a big deal at these big corporations. Seems like there is always someone higher in the food chain who wants a spreadsheet to tell them what you&#8217;re actually doing, and if you&#8217;re hitting your targets. As annoying and cumbersome as it may be, it’s very important that you produce and provide statistics that are accurate, and up to date, so I&#8217;ve got a quick solution that will make any boss somewhat happy&#8230;<br />
<span id="more-124"></span><br />
A wise man once told me, if you do something more than once, it’s worth automating it. So I took that idea and ran a marathon with it. I automate everything. I hate repetition so I&#8217;d rather invest 3 times the effort and write a script than do it 10 times over. Simple maths really.<br />
Oracle db&#8217;s are everywhere, I blog about them, I work with them and I fight with too. If you want the basics on getting ruby and oracle to work, read my other blog post which is <a href="http://mishmashmoo.com/blog/?p=5">here</a>.</p>
<p>Once you have that established, install <a href="http://www.wampserver.com/en/">wamp</a>, which is an apache webserver, mysql and php rolled into one package.</p>
<p>Now what we&#8217;re going to do here is use the script from my other post, and enhance it somewhat. In my scenario I have a spreadsheet with NFR&#8217;s. They state the Group name, Transaction Name &amp; Response Time. I want my report to show these values (as the source) and then display the values that are in the database so my boss can compare the results and see how the system is performing.</p>
<p>Let’s assume your spreadsheet looks likes this:</p>
<table border="1">
<tr>
<td>Group</td>
<td>Transaction</td>
<td>Response Time</td>
</tr>
<tr>
<td>01.Payment</td>
<td>Submit Payment</td>
<td>12 seconds</td>
</tr>
</table>
<p>Now in my master database, my system keeps a log of when a payment changed status from entered, to submitted. Like most systems, it’s a timestamp and it will show the changed status of that particular payment x amount of times, based on how many status&#8217;s it goes through. I&#8217;ve seen this in many systems, and it’s quite kosher, or halal (depending on where you come from!). </p>
<p>Luckily I have an sql query that will do this for me, but it just presents all the payments in the date range I need, but I need the 95th Percentile of this&#8230;.luckily sql can do this for you and here is something I whipped up&#8230;with some help from my colleagues and maybe a DBA or 2..</p>

<div class="wp_syntax"><div class="code"><pre class="sql"><span style="color: #993333; font-weight: bold;">SELECT</span> trunc<span style="color: #66cc66;">&#40;</span>percentile_cont<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.95</span><span style="color: #66cc66;">&#41;</span> WITHIN <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bt2<span style="color: #66cc66;">.</span>logtime <span style="color: #66cc66;">-</span> bt1<span style="color: #66cc66;">.</span>logtime<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">24</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">3600</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>count<span style="color: #66cc66;">&#40;</span>bt1<span style="color: #66cc66;">.</span>trans_num<span style="color: #66cc66;">&#41;</span>
        <span style="color: #993333; font-weight: bold;">FROM</span> AUDIT_LOG bt1<span style="color: #66cc66;">,</span> AUDIT_LOG bt2<span style="color: #66cc66;">,</span> 
        <span style="color: #993333; font-weight: bold;">WHERE</span> bt1<span style="color: #66cc66;">.</span>TRANS_NUM <span style="color: #66cc66;">=</span> bt2<span style="color: #66cc66;">.</span>TRANS_NUM
        <span style="color: #993333; font-weight: bold;">AND</span> bt1<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">STATUS</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SUBMITTED'</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #993333; font-weight: bold;">AND</span> bt2<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">STATUS</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'APPROVED'</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #993333; font-weight: bold;">AND</span> at<span style="color: #66cc66;">.</span>LOG_TIMESTAMP <span style="color: #66cc66;">&gt;</span> TO_DATE<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&quot;+datetimefrom +&quot;'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'YYYY-MM-DD HH24:MI:SS'</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #993333; font-weight: bold;">AND</span> at<span style="color: #66cc66;">.</span>LOG_TIMESTAMP <span style="color: #66cc66;">&lt;</span> TO_DATE<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&quot;+datetimeto +&quot;'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'YYYY-MM-DD HH24:MI:SS'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Pretty straight forward, You will obviously need to change it for your own application but it a start.<br />
So this returns 1 value, the 95th percentile, truncated to 1 decimal place, and the number of samples (count) that it evaluated the figure on. </p>
<p>So with those 3 components, we have enough to build a ruby script that will read the spreadsheet, and create a report with the results based on that query. </p>
<p>Ruby script&#8230;</p>
<p>Ok so now we need to make a functions file. lets say, that there are 100 NFR&#8217;s. Each nfr, is based on a different transaction, each one of those transactions needs a separate sql query. So we will need a functions file&#8230;with those queries that our script can call. </p>
<p>Name the following file <b>sql.rb</b></p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'OCI8'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> function<span style="color:#006600; font-weight:bold;">&#40;</span>name,datetimefrom,datetimeto<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">case</span> name
       <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;submit_payment&quot;</span>
              <span style="color:#ff6633; font-weight:bold;">$nfr_name</span> = <span style="color:#996600;">&quot;Submit Payment&quot;</span>
              <span style="color:#ff6633; font-weight:bold;">$query</span>=<span style="color:#996600;">&quot;select trunc(percentile_cont(0.95) WITHIN GROUP (ORDER BY ((bt2.logtime - bt1.logtime) * 24 * 3600 )),1),count(bt1.trans_num)
        FROM AUDIT_LOG bt1, AUDIT_LOG bt2, 
        WHERE bt1.TRANS_NUM = bt2.TRANS_NUM
        AND bt1.STATUS in ('SUBMITTED')
        AND bt2.STATUS in ('APPROVED')
        AND at.LOG_TIMESTAMP &gt; TO_DATE('&quot;</span><span style="color:#006600; font-weight:bold;">+</span>datetimefrom <span style="color:#006600; font-weight:bold;">+</span><span style="color:#996600;">&quot;','YYYY-MM-DD HH24:MI:SS')
        AND at.LOG_TIMESTAMP &lt; TO_DATE('&quot;</span><span style="color:#006600; font-weight:bold;">+</span>datetimeto <span style="color:#006600; font-weight:bold;">+</span><span style="color:#996600;">&quot;','YYYY-MM-DD HH24:MI:SS')&quot;</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now the script, which requires the above file.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'OCI8'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'date.rb'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'sql.rb'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'time'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'functions.rb'</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#get the current time</span>
t= <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
&nbsp;
datetimefrom = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
datetimeto = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>
filename = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>
full_filename = <span style="color:#996600;">&quot;c:<span style="color:#000099;">\\</span>wamp<span style="color:#000099;">\\</span>www<span style="color:#000099;">\\</span>reports<span style="color:#000099;">\\</span>&quot;&quot;</span> <span style="color:#006600; font-weight:bold;">+</span>filename<span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;.csv&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#put the headers of the file in first</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>full_filename,<span style="color:#996600;">&quot;a&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>the_file<span style="color:#006600; font-weight:bold;">|</span>
  the_file.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Group,Transaction,Date/Time From, Date/Time To,RT,95th Percentile,Sample Size&quot;</span>
  the_file.<span style="color:#9900CC;">close</span>
<span style="color:#9966CC; font-weight:bold;">end</span>  
&nbsp;
<span style="color:#008000; font-style:italic;">#add the function names into the array</span>
<span style="color:#9966CC; font-weight:bold;">class</span> Nfrlist <span style="color:#006600; font-weight:bold;">&lt;</span>
&nbsp;
 <span style="color:#CC00FF; font-weight:bold;">Struct</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:group</span>, <span style="color:#ff3333; font-weight:bold;">:transaction</span>, <span style="color:#ff3333; font-weight:bold;">:rt</span>, <span style="color:#ff3333; font-weight:bold;">:function</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># define new array to hold the records</span>
nfr = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># open the csv file</span>
f = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;nfrs.csv&quot;</span>, <span style="color:#996600;">&quot;r&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># loop through each record in the csv file, adding</span>
<span style="color:#008000; font-style:italic;"># each record to our array.</span>
f.<span style="color:#9900CC;">each_line</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># each line has fields separated by commas, so split those fields</span>
  fields = line.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">','</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># create a new Person</span>
  <span style="color:#CC0066; font-weight:bold;">p</span> = Nfrlist.<span style="color:#9900CC;">new</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># do a little work here to get rid of double-quotes and blanks</span>
    <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">group</span> = fields<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">tr_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&quot;'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>
    <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">transaction</span> = fields<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">tr_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&quot;'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>
    <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">rt</span> = fields<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">tr_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&quot;'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>
    <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">function</span> = fields<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">tr_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&quot;'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>
    nfr.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#41;</span>   
&nbsp;
&nbsp;
    <span style="color:#008000; font-style:italic;">#array declreation inside loop to clear the array on each iteration in the loop.</span>
    <span style="color:#ff6633; font-weight:bold;">$lines</span>= <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#ff6633; font-weight:bold;">$nfr</span>=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#ff6633; font-weight:bold;">$blah</span>=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#ff6633; font-weight:bold;">$percentile</span>=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#ff6633; font-weight:bold;">$query</span>=<span style="color:#996600;">&quot;&quot;</span>
&nbsp;
    <span style="color:#008000; font-style:italic;">#call the function from the other .rb file</span>
    function<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">function</span>,datetimefrom,datetimeto<span style="color:#006600; font-weight:bold;">&#41;</span>  
&nbsp;
      <span style="color:#008000; font-style:italic;">#if the name of the function starts with CPR connect to the cpr database,   otherwise go to BTR</span>
      <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">/</span>^cpr<span style="color:#006600; font-weight:bold;">+</span>.\w<span style="color:#006600; font-weight:bold;">+</span>$<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">function</span><span style="color:#006600; font-weight:bold;">&#41;</span>  <span style="color:#9966CC; font-weight:bold;">then</span>
         conn = OCI8.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'login'</span>, <span style="color:#996600;">'password'</span>, <span style="color:#996600;">'database1.world'</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
      <span style="color:#9966CC; font-weight:bold;">else</span>
          conn = OCI8.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'login'</span>, <span style="color:#996600;">'password'</span>, <span style="color:#996600;">'database2.world'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>    
    <span style="color:#008000; font-style:italic;">#execute the sql query</span>
    <span style="color:#008000; font-style:italic;">#if the query is blank(for items that are not required for the db, but need to have a line item in the rrport) then skip this bit...</span>
&nbsp;
   <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#ff6633; font-weight:bold;">$query</span> != <span style="color:#996600;">&quot;&quot;</span> <span style="color:#9966CC; font-weight:bold;">then</span>
    cursor = conn.<span style="color:#CC0066; font-weight:bold;">exec</span><span style="color:#006600; font-weight:bold;">&#40;</span>$query<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">while</span> r = cursor.<span style="color:#9900CC;">fetch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
       <span style="color:#008000; font-style:italic;">#add each row to the lines array, separate by tab.</span>
       <span style="color:#ff6633; font-weight:bold;">$lines</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>p.<span style="color:#9900CC;">group</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">transaction</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> datetimefrom <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> datetimeto <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">rt</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> r.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;,&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    cursor.<span style="color:#9900CC;">close</span>
  <span style="color:#9966CC; font-weight:bold;">end</span> 
&nbsp;
    <span style="color:#ff6633; font-weight:bold;">$percentile</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#ff6633; font-weight:bold;">$lines</span>
&nbsp;
&nbsp;
<span style="color:#008000; font-style:italic;">#now write it to a file. </span>
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>full_filename,<span style="color:#996600;">&quot;a&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>the_file<span style="color:#006600; font-weight:bold;">|</span>
  the_file.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#ff6633; font-weight:bold;">$percentile</span>
<span style="color:#9966CC; font-weight:bold;">end</span>  
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Now change your csv, to have a colum which has the name of the case statement name in your sql.rb file for that particular function. </p>
<table border="1">
<tr>
<td>Group</td>
<td>Transaction</td>
<td>Response Time</td>
<td>function</td>
</tr>
<tr>
<td>01.Payment</td>
<td>Submit Payment</td>
<td>12 seconds</td>
<td>submit_payment</tr>
</table>
<p>Once that’s done, you will be able to run that script. It will read the nfr.csv file, and read each column and save it in the struct. Then you can call it via the struct name, and evaluate on it. </p>
<p>As you can see there are ARGV&#8217;s for some info. Those are so this ruby file can be run remotely&#8230;.say from a web interface&#8230;.</p>
<p>Build your php&#8230;<br />
My php contains some calendar scripts, there are hundreds on the net…just have a poke around to find one that suits you.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;script language</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;calendar.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;somewhere.php&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//get class into the page</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tc_calendar.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//instantiate class and set properties</span>
<span style="color: #000033;">$dateFrom</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> tc_calendar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;date1&quot;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$dateFrom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIcon</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;images/iconCalendar.gif&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$dateFrom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Time From (HH24:MI:SS): &lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>timefrom<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//output the calendar</span>
<span style="color: #000033;">$dateFrom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	 
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;P&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$dateTo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> tc_calendar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;date2&quot;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$dateTo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIcon</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;images/iconCalendar.gif&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$dateTo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Time To (HH24:MI:SS): &lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>timeto<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//output the calendar</span>
<span style="color: #000033;">$dateTo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	  
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;throughput&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Yes&quot;</span><span style="color: #339933;">&gt;</span> Throughput Report <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;responsetime&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Yes&quot;</span><span style="color: #339933;">&gt;</span> Response <span style="color: #990000;">Time</span> Report <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Send it!&quot;</span><span style="color: #339933;">&gt;&lt;/</span>p<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Now the php page that the form will submit to&#8230;called <b>somewhere.php</b></p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
date_default_timezone_set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Australia/Sydney&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$filenameDate</span><span style="color: #339933;">=</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dmy_His&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$datefrom</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date1&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date1&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$timefrom</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;timefrom&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000033;">$dateto</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date2&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date2&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$timeto</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;timeto&quot;</span><span style="color: #009900;">&#93;</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><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'responsetime'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;responsetime.rb <span style="color: #000099; font-weight: bold;">\&quot;</span>$datefrom $timefrom<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>$dateto $timeto<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>ResponseTime_$filenameDate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000033;">$file</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ResponseTime_$filenameDate.csv&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='http://localhost/reports/ResponseTime_&quot;</span> <span style="color: #339933;">.</span><span style="color: #000033;">$filenameDate</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.csv'&gt;Get Response Time Report&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'throughput'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;throughput.rb <span style="color: #000099; font-weight: bold;">\&quot;</span>$datefrom $timefrom<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>$dateto $timeto<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>Throughput_$filenameDate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000033;">$file2</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Throughput_$filenameDate.csv&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&lt;a href='http://localhost/reports/Throughput_&quot;</span> <span style="color: #339933;">.</span><span style="color: #000033;">$filenameDate</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.csv'&gt;Get Throughput Report&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now give the URL of your wamp server page to your boss, and he can specify his own date/time range for the report, and it will present itself to him. It will show him something like this </p>
<table border="1">
<tr>
<td>Group</td>
<td>Transaction</td>
<td>Response Time</td>
<td>95th Percentile (from db)</td>
</tr>
<tr>
<td>01.Payment</td>
<td>Submit Payment</td>
<td>12 seconds</td>
<td>37.7</tr>
</table>
<p>Now you need worry bout reporting, as its in the hands of his trusty browser, and your script. </p>
<p>You can keep adding to this, by adding more case statement&#8217;s in the sql.rb file, and making sure you mention the name of the case statement in a row of your nfr.csv.<br />
Then you will never have to touch the script. </p>
<p>Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=124</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>connect to mysql with ruby</title>
		<link>http://mishmashmoo.com/blog/?p=117</link>
		<comments>http://mishmashmoo.com/blog/?p=117#comments</comments>
		<pubDate>Wed, 17 Feb 2010 22:13:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=117</guid>
		<description><![CDATA[Often, when I begin a new gig, I have a few little tools I install to make my job that little bit more efficient.
One of these would be a wamp server and the ruby installer, along with the usual gems I often utilise. The wamp server is great to store data for scripts I&#8217;m writing, [...]]]></description>
			<content:encoded><![CDATA[<p>Often, when I begin a new gig, I have a few little tools I install to make my job that little bit more efficient.<br />
One of these would be a wamp server and the ruby installer, along with the usual gems I often utilise. The wamp server is great to store data for scripts I&#8217;m writing, and a little ruby here and there never hurt anybody!<br />
It occurred to me that I&#8217;d never actually blogged how to get ruby and mysql connectivity. As with anything ruby related, its easy but it does require a few key steps..<br />
<span id="more-117"></span><br />
You&#8217;ll obviously need ruby installed, and the wamp server. Once that’s done, install the <strong>mysql</strong> gem:</p>

<div class="wp_syntax"><div class="code"><pre>c:\&gt;gem install mysql --no-ri --no-rdoc</pre></div></div>

<p>This will install without ri and rdocs. Some definition errors will occur if you install the gem with ri and rdoc, this is due to the location of mysql, however it&#8217;s fine, it&#8217;ll still work!</p>
<p>Once that&#8217;s done, locate your copy of <strong>libmysql.dll</strong>. It&#8217;s usually found in c:\wamp\bin\mysqlmysq<strong>VERSIONl</strong>\bin<br />
Take a copy of it and dump it in your location of ruby. Generally <strong>C:\Ruby\bin</strong>.</p>
<p>Ok so that&#8217;s that part done. Now for the serious stuff&#8230;<br />
Here&#8217;s the code. Its pretty self explanatory.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">query = <span style="color:#996600;">&quot;select columnA, ColumnB from table&quot;</span>
<span style="color:#9966CC; font-weight:bold;">begin</span>
     dbh = Mysql.<span style="color:#9900CC;">real_connect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;localhost&quot;</span>, <span style="color:#996600;">&quot;login&quot;</span>, <span style="color:#996600;">&quot;password&quot;</span>, <span style="color:#996600;">&quot;databaseName&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
     <span style="color:#008000; font-style:italic;"># get server version string and display it</span>
     <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Server version: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> dbh.<span style="color:#9900CC;">get_server_info</span>
   <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">Mysql::Error</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
     <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Error code: #{e.errno}&quot;</span>
     <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Error message: #{e.error}&quot;</span>
     <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Error SQLSTATE: #{e.sqlstate}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> e.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;sqlstate&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#9966CC; font-weight:bold;">ensure</span>
      res = dbh.<span style="color:#9900CC;">query</span><span style="color:#006600; font-weight:bold;">&#40;</span>query<span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#9966CC; font-weight:bold;">while</span> row = res.<span style="color:#9900CC;">fetch_row</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> row<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> row<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
   <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Number of rows returned: #{res.num_rows}&quot;</span>
   res.<span style="color:#9900CC;">free</span>
     <span style="color:#008000; font-style:italic;"># disconnect from server</span>
     dbh.<span style="color:#9900CC;">close</span> <span style="color:#9966CC; font-weight:bold;">if</span> dbh
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And thats it!<br />
Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=117</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>javascript error when running selenium test suite</title>
		<link>http://mishmashmoo.com/blog/?p=114</link>
		<comments>http://mishmashmoo.com/blog/?p=114#comments</comments>
		<pubDate>Wed, 10 Feb 2010 00:13:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=114</guid>
		<description><![CDATA[A strange problem occurred when I was running one of my selenium test suites. The test would run fine for my first testcase (that is, the first &#8220;method&#8221;). If you know a little about how selenium works, you&#8217;ll know that the teardown method is called after each method.
The teardown basically grabs any errors that occurs [...]]]></description>
			<content:encoded><![CDATA[<p>A strange problem occurred when I was running one of my selenium test suites. The test would run fine for my first testcase (that is, the first &#8220;method&#8221;). If you know a little about how selenium works, you&#8217;ll know that the teardown method is called after each method.<br />
The teardown basically grabs any errors that occurs and kills the browser session, thus opening a new session in your next method. The issue that was occurring was this annoying JavaScript error being pulled from Internet Explorer, saying it cannot run scripts on the page. It halted my script and I had no way to get to the following methods&#8230;so after a little digging around I found a solution&#8230;<br />
<span id="more-114"></span><br />
All you need to do, is replace your current teardown method with this</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">    <span style="color:#9966CC; font-weight:bold;">def</span> teardown
		<span style="color:#0066ff; font-weight:bold;">@selenium</span>.<span style="color:#9900CC;">close</span>
		<span style="color:#0066ff; font-weight:bold;">@selenium</span>.<span style="color:#9900CC;">stop</span>
    assert_equal <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#0066ff; font-weight:bold;">@verification_errors</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>That should fix it&#8230;<br />
enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=114</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Frequently used Selenium Commands</title>
		<link>http://mishmashmoo.com/blog/?p=100</link>
		<comments>http://mishmashmoo.com/blog/?p=100#comments</comments>
		<pubDate>Thu, 28 Jan 2010 03:26:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=100</guid>
		<description><![CDATA[So I&#8217;ve been dabling with Selenium again&#8230;I love open source, but the lack of documentation is very frustrating. Hitting F1 in Loadrunner was taken for granted, so if I find something useful, as a fellow open-sourcer, I&#8217;m going to share it. Hopefully this can be of some use to you all.
Enjoy!



	assignId(&#8221;Locator&#8221;,&#8221;String&#8221;)	
	Temporarily sets the &#8220;id&#8221; attribute [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been dabling with Selenium again&#8230;I love open source, but the lack of documentation is very frustrating. Hitting F1 in Loadrunner was taken for granted, so if I find something useful, as a fellow open-sourcer, I&#8217;m going to share it. Hopefully this can be of some use to you all.<br />
Enjoy!<br />
<span id="more-100"></span></p>
<table border=1 width="75%">
<tr>
<td width="10%">	assignId(&#8221;Locator&#8221;,&#8221;String&#8221;)	</td>
<td>	Temporarily sets the &#8220;id&#8221; attribute of the specified element	</td>
</tr>
<tr>
<td width="10%">	capture Screenshot (&#8221;File name&#8221;)	</td>
<td>	Captures a PNG screenshot to thespecified file.	</td>
</tr>
<tr>
<td width="10%">	Check(&#8221;Locator&#8221;)	</td>
<td>	Check a toggle-button(checkbox/radio)	</td>
</tr>
<tr>
<td width="10%">	click(&#8221;Locator&#8221;)	</td>
<td>	Clicks on a link, button, checkboxor radio button.	</td>
</tr>
<tr>
<td width="10%">	clickAt(&#8221;Locator&#8221;,&#8221;Coordinate String&#8221;)	</td>
<td>	Clicks on a link, button, checkboxor radio button.	</td>
</tr>
<tr>
<td width="10%">	close()	</td>
<td>	Simulates the user clicking the&#8221;close&#8221; button in the title bar of a popup window or tab.	</td>
</tr>
<tr>
<td width="10%">	doubleClick(&#8221;Locator&#8221;)	</td>
<td>	Double clicks on a link, button,checkbox or radio button.	</td>
</tr>
<tr>
<td width="10%">	doubleClickAt(&#8221;Locator&#8221;,&#8221;Coordinate String&#8221;)	</td>
<td>	Double clicks on a link, button,checkbox or radio button.	</td>
</tr>
<tr>
<td width="10%">	getAlert()	</td>
<td>	Retrieves the message of aJavaScript alert generated during the previous action, or fail if there were no alerts.	</td>
</tr>
<tr>
<td width="10%">	getAllButtons()	</td>
<td>	Returns the IDs of all buttons onthe page.	</td>
</tr>
<tr>
<td width="10%">	getAllFields()	</td>
<td>	Returns the IDs of all input fieldson the page.	</td>
</tr>
<tr>
<td width="10%">	getAllLinks()	</td>
<td>	Returns the IDs of all links on the page.	</td>
</tr>
<tr>
<td width="10%">	getAllWindowIds()	</td>
<td>	Returns the IDs of all windows that the browser knows about.	</td>
</tr>
<tr>
<td width="10%">	getAllWindowNames()	</td>
<td>	Returns the names of all windows that the browser knows about.	</td>
</tr>
<tr>
<td width="10%">	getAllWindowTitles()	</td>
<td>	Returns the titles of all windows that the browser knows about.	</td>
</tr>
<tr>
<td width="10%">	getAttribute(&#8221;Attribute Locator&#8221;)	</td>
<td>	Gets the value of an element attribute.	</td>
</tr>
<tr>
<td width="10%">	getBodyText()	</td>
<td>	Gets the entire text of the page.	</td>
</tr>
<tr>
<td width="10%">	getConfirmation()	</td>
<td>	Retrieves the message of a JavaScript confirmation dialog generated during the previous action.	</td>
</tr>
<tr>
<td width="10%">	getCookie()	</td>
<td>	Return all cookies of the current page under test.	</td>
</tr>
<tr>
<td width="10%">	getElementHeight(&#8221;Locator&#8221;)	</td>
<td>	Retrieves the height of an element	</td>
</tr>
<tr>
<td width="10%">	getElementPositionLeft(&#8221;Locator&#8221;)	</td>
<td>	Retrieves the horizontal position of an element	</td>
</tr>
<tr>
<td width="10%">	getElementPositionTop(&#8221;Locator&#8221;)	</td>
<td>	Retrieves the vertical position of an element	</td>
</tr>
<tr>
<td width="10%">	getElementWidth(&#8221;Locator&#8221;)	</td>
<td>	Retrieves the width of an element	</td>
</tr>
<tr>
<td width="10%">	getEval(&#8221;JS Expression&#8221;)	</td>
<td>	Gets the result of evaluating the specified JavaScript snippet.	</td>
</tr>
<tr>
<td width="10%">	getLocation()	</td>
<td>	Gets the absolute URL of the current page.	</td>
</tr>
<tr>
<td width="10%">	getMouseSpeed()	</td>
<td>	Returns the number of pixels between &#8220;mousemove&#8221; events during dragAndDrop commands (default=10).	</td>
</tr>
<tr>
<td width="10%">	getPrompt()	</td>
<td>	Retrieves the message of a JavaScript question prompt dialog generated during the previous action.	</td>
</tr>
<tr>
<td width="10%">	getSelectedId(&#8221;Select Locator&#8221;)	</td>
<td>	Gets option element ID for selected option in the specified select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedIds(&#8221;Select Locator&#8221;)	</td>
<td>	Gets all option element IDs for selected options in the specified select or multi-select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedIndex(&#8221;Select Locator&#8221;)	</td>
<td>	Gets option index (option number, starting at 0) for selected option in the specified select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedIndexes(&#8221;Select Locator&#8221;)	</td>
<td>	Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedLable(&#8221;Select Locator&#8221;)	</td>
<td>	Gets option label (visible text) for selected option in the specified select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedLables(&#8221;Select Locator&#8221;)	</td>
<td>	Gets all option labels (visible text) for selected options in the specified select or multi-select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedValue(&#8221;Select Locator&#8221;)	</td>
<td>	Gets option value (value attribute) for selected option in the specified select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedValues(&#8221;Select Locator&#8221;)	</td>
<td>	Gets all option values (value attributes) for selected options in the specified select or multi-select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectOptions(&#8221;Select Locator&#8221;)	</td>
<td>	Gets all option labels in the specified select drop-down.	</td>
</tr>
<tr>
<td width="10%">	getSpeed()	</td>
<td>	Get execution speed (i.e., get the millisecond length of the delay following each selenium operation).	</td>
</tr>
<tr>
<td width="10%">	getTable(&#8221;Table Cell Address”)	</td>
<td>	Gets the text from a cell of a table.	</td>
</tr>
<tr>
<td width="10%">	getText(&#8221;Locator&#8221;)	</td>
<td>	Gets the text of an element.	</td>
</tr>
<tr>
<td width="10%">	getTitle()	</td>
<td>	Gets the title of the current page.	</td>
</tr>
<tr>
<td width="10%">	getValue(&#8221;Locator&#8221;)	</td>
<td>	Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).	</td>
</tr>
<tr>
<td width="10%">	get Whether This Frame MatchFrameExpression(&#8221;Current Frame&#8221;,&#8221;Target&#8221;)	</td>
<td>	Determine whether current/locator identify the frame containing this running code	</td>
</tr>
<tr>
<td width="10%">	get Whether This Window MatchWindowExpression(&#8221;CurrentWindow&#8221;,&#8221;Target&#8221;)	</td>
<td>	Determine whether currentWindow String plus target identify the window containing this running code.	</td>
</tr>
<tr>
<td width="10%">	goBack()	</td>
<td>	Simulates the user clicking the &#8220;back&#8221; button on their browser.	</td>
</tr>
<tr>
<td width="10%">	highlight(&#8221;Locator&#8221;)	</td>
<td>	Briefly changes the backgroundColor of the specified element yellow.	</td>
</tr>
<tr>
<td width="10%">	isAlertPresent()	</td>
<td>	Has an alert occurred?	</td>
</tr>
<tr>
<td width="10%">	isChecked(&#8221;Locator&#8221;)	</td>
<td>	Gets whether a toggle-button (checkbox/radio) is checked.	</td>
</tr>
<tr>
<td width="10%">	isConfirmationPresent()	</td>
<td>	Has confirm() been called?	</td>
</tr>
<tr>
<td width="10%">	isEditable(&#8221;Locator&#8221;)	</td>
<td>	Determines whether the specified input element is editable, ie hasn&#8217;t been disabled.	</td>
</tr>
<tr>
<td width="10%">	isElementPresent(&#8221;Locator&#8221;)	</td>
<td>	Verifies that the specified element is somewhere on the page.	</td>
</tr>
<tr>
<td width="10%">	isPromptPresent()	</td>
<td>	Has a prompt occurred?	</td>
</tr>
<tr>
<td width="10%">	isSomethingSelected(&#8221;Locator&#8221;)	</td>
<td>	Determines whether some option in a drop-down menu is selected.	</td>
</tr>
<tr>
<td width="10%">	isTextPresent(&#8221;Pattern&#8221;)	</td>
<td>	Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.	</td>
</tr>
<tr>
<td width="10%">	isVisible(&#8221;Locator&#8221;)	</td>
<td>	Determines if the specified element is visible.	</td>
</tr>
<tr>
<td width="10%">	open(&#8221;URL&#8221;)	</td>
<td>	Opens an URL in the test frame.	</td>
</tr>
<tr>
<td width="10%">	openWindow(&#8221;URL&#8221;,&#8221;WindowID&#8221;)	</td>
<td>	Opens a popup window (if a window with that ID isn&#8217;t already open).	</td>
</tr>
<tr>
<td width="10%">	refresh()	</td>
<td>	Simulates the user clicking the &#8220;Refresh&#8221; button on their browser.	</td>
</tr>
<tr>
<td width="10%">	removeAllSelections(&#8221;Locator&#8221;)	</td>
<td>	Unselects all of the selected options in a multi-select element.	</td>
</tr>
<tr>
<td width="10%">	removeSelection(&#8221;Locator&#8221;,&#8221;Option Locator&#8221;)	</td>
<td>	Remove a selection from the set of selected options in a multi-select element using an option locator.	</td>
</tr>
<tr>
<td width="10%">	select(&#8221;Select Locator&#8221;,&#8221;Option Locator&#8221;)	</td>
<td>	Select an option from a drop-down using an option locator.	</td>
</tr>
<tr>
<td width="10%">	selectFrame(&#8221;Locator&#8221;)	</td>
<td>	Selects a frame within the current window.	</td>
</tr>
<tr>
<td width="10%">	selectWindow(&#8221;WindowID&#8221;)	</td>
<td>	Selects a popup window; once a popup window has been selected, all commands go to that window.	</td>
</tr>
<tr>
<td width="10%">	setSpeed(&#8221;Value&#8221;)	</td>
<td>	Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation).	</td>
</tr>
<tr>
<td width="10%">	setTimeout(&#8221;Time&#8221;)	</td>
<td>	Specifies the amount of time that Selenium will wait for actions to complete.	</td>
</tr>
<tr>
<td width="10%">	start()	</td>
<td>	Launches the browser with a new Selenium session 	</td>
</tr>
<tr>
<td width="10%">	stop()	</td>
<td>	Ends the test session, killing the browser	</td>
</tr>
<tr>
<td width="10%">	submit(&#8221;Form Locator&#8221;)	</td>
<td>	Submit the specified form.	</td>
</tr>
<tr>
<td width="10%">	type(&#8221;Locator&#8221;,&#8221;Value&#8221;)	</td>
<td>	Sets the value of an input field, as though you typed it in.	</td>
</tr>
<tr>
<td width="10%">	unCheck(&#8221;Locator&#8221;)	</td>
<td>	Uncheck a toggle-button (checkbox/radio)	</td>
</tr>
<tr>
<td width="10%">	waitForCondition(&#8221;JavaScript&#8221;,&#8221;Timeout&#8221;)	</td>
<td>	Runs the specified JavaScript snippet repeatedly until it evaluates to &#8220;true&#8221;.	</td>
</tr>
<tr>
<td width="10%">	waitForFrameToLoad(&#8221;Frame Address&#8221;,&#8221;Timeout&#8221;)	</td>
<td>	Waits for a new frame to load.	</td>
</tr>
<tr>
<td width="10%">	waitForPageToLoad(&#8221;Timeout&#8221;)	</td>
<td>	Waits for a new page to load.	</td>
</tr>
<tr>
<td width="10%">	waitForPopUp(&#8221;WindowID&#8221;,&#8221;Timeout&#8221;)	</td>
<td>	Waits for a popup window to appear and load up.	</td>
</tr>
<tr>
<td width="10%">	windowFocus()	</td>
<td>	Gives focus to the currently selected window	</td>
</tr>
<tr>
<td width="10%">	windowMaximize()	</td>
<td>	Resize currently selected window to take up the entire screen	</td>
</tr>
</table>
<p>  </body><br />
</html></p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=100</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>setting system time :: vugen</title>
		<link>http://mishmashmoo.com/blog/?p=88</link>
		<comments>http://mishmashmoo.com/blog/?p=88#comments</comments>
		<pubDate>Fri, 06 Nov 2009 00:13:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=88</guid>
		<description><![CDATA[Quite often I get personally contacted by people requiring some assistance or just wanting to ask me for my advice. It&#8217;s a nice ego boost, but also a very important aspect of the industry that should be maintained. My beliefs are we should do what we can to assist others, and with the use of [...]]]></description>
			<content:encoded><![CDATA[<p>Quite often I get personally contacted by people requiring some assistance or just wanting to ask me for my advice. It&#8217;s a nice ego boost, but also a very important aspect of the industry that should be maintained. My beliefs are we should do what we can to assist others, and with the use of the internet, we have a great medium to share and distribute information, with such things like twitter, Google talk and, well my blog, are all making it possible for a total stranger to speak to another and get the help he/she needs.</p>
<p>Recently, a now friend of mine, Roberto Brusa struck up a conversation about changing the system time in vugen. He was making a system call, which is fine, its a great way to do it, but he did mention that he did not want the annoying cmd pop up and probed me for a possible alternative. Now I&#8217;ve never done this before but after bouncing ideas off each other I suggested that in theory, it should be possible, through the usage of the win32api, to manipulate the tme&#8230;We found that this statment was true, and proved it with the following&#8230;<br />
<span id="more-88"></span><br />
Not many performance testers know about this little trick, but I have used it a few times. its the <strong>lr_load_dll()</strong> function. It allows you to load a dll into your <strong>vuser_init()</strong>, and once loaded, you can call any function that is inside that dll anytime in your script.<br />
The hardest part, is finding out what the dll does, what functions can be called, and the format in which they must be placed. A quick Google search should solve your issues, or jump on the msdn. </p>
<p>Now, the <strong>kernel32.dll</strong> is responsible for setting the system time, as well as many other things, and explicitly calling <strong>SetSystemTime</strong> allows full manipulation. With this information and some intuitive Google searching from Roberto and I, collectively we managed to come up with this script, which sets the system time to whatever you want, right down to the millisecond!. </p>
<p><strong>vuser init</strong><br />
note: I declare all my variables before the vuser_init function, for neatness.</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #993333;">double</span> atof <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #993333;">string</span><span style="color: #009900;">&#41;</span>;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> _SYSTEMTIME <span style="color: #009900;">&#123;</span>
  WORD wYear;
  WORD wMonth;
  WORD wDayOfWeek;
  WORD wDay;
  WORD wHour;
  WORD wMinute;
  WORD wSecond;
  WORD wMilliseconds;
<span style="color: #009900;">&#125;</span>SYSTEMTIME, <span style="color: #339933;">*</span>PSYSTEMTIME;
vuser_init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   lr_load_dll<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;kernel32.dll&quot;</span><span style="color: #009900;">&#41;</span>;
   <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Action</strong><br />
Set your values, and call the function&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="c">Action<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   SYSTEMTIME st;
   st.<span style="color: #202020;">wYear</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2000</span>;
   st.<span style="color: #202020;">wMonth</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span>;
   st.<span style="color: #202020;">wDay</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12</span>;
   st.<span style="color: #202020;">wHour</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">16</span>;
   st.<span style="color: #202020;">wMinute</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span>;
   st.<span style="color: #202020;">wSecond</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span>;
   st.<span style="color: #202020;">wMilliseconds</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">55</span>;
&nbsp;
   <span style="color: #666666; font-style: italic;">//call the function for the dll, parsing the input value of st paramater</span>
   SetSystemTime<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>st<span style="color: #009900;">&#41;</span>;
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Use it at your will!<br />
Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=88</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>find multiple values of text in a block of text :: perl</title>
		<link>http://mishmashmoo.com/blog/?p=71</link>
		<comments>http://mishmashmoo.com/blog/?p=71#comments</comments>
		<pubDate>Wed, 14 Oct 2009 05:54:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=71</guid>
		<description><![CDATA[From time to time I&#8217;m asked to do an odd job here and there, so I have a whole bunch of little snippets of scripts that I have created for people, to make their jobs faster, easier and more efficient. This last one, I was pretty pleased with, as it is very dynamic in what [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time I&#8217;m asked to do an odd job here and there, so I have a whole bunch of little snippets of scripts that I have created for people, to make their jobs faster, easier and more efficient. This last one, I was pretty pleased with, as it is very dynamic in what it can do.<br />
Basically, the requirements were very vague&#8211;</p>
<p>&#8220;We need to find a range of values in a block of text.<br />
The block of text will sometimes be 2 lines, or can be up to 20 lines.<br />
The files we are searching through are in all different formats.<br />
We would like to do multiple searches in one action.<br />
We need to search for multiple values in a search, and only pass if all values are found within the line count we specify.<br />
We would like our search data to be in a separate file we can build and run the search against this.<br />
We would like to have total control over what file to search through.<br />
We need to know the line number it was found on, when it is found.<br />
If possible, can we run this on a windows box, and on a mainframe server to which we can&#8217;t install apps&#8221;</p>
<p>So with all these in mind, I was off to write a script. I wanted to use ruby, but knew it wasn’t native to mainframe&#8217;s, so I opted for Perl instead. My Perl skills are not what I would like them to be, so feel free to update/criticise/chop my code <img src='http://mishmashmoo.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<span id="more-71"></span><br />
So without further ado, here is my script. It meets all the requirements noted above, and is simple enough to understand without a detailed explanation.</p>

<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;"># #########################################################################</span>
<span style="color: #666666; font-style: italic;">#Perl search multiple lines</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Usage    : find.pl</span>
<span style="color: #666666; font-style: italic;"># Options  :</span>
<span style="color: #666666; font-style: italic;">#     $inputFile    Space seperated file, up to 6 ARGV's of text to search for (slashes will be auto escaped)</span>
<span style="color: #666666; font-style: italic;">#     $readFile    The location of the file to search</span>
<span style="color: #666666; font-style: italic;">#     $maxLines   The amount of lines in block to search for All Args</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#     The script will search for text accross the entire file for all input data starting with ARGV0 </span>
<span style="color: #666666; font-style: italic;">#       If ARGV0 is found, it will search for the next $maxLines for ARGV2, if found, will search for ARGV3, if found </span>
<span style="color: #666666; font-style: italic;">#       will search for ARGV4 etc etc.  - max ARGV's = 6.</span>
<span style="color: #666666; font-style: italic;">#      A success is only when all ARGV's are found. If you input only 2 or 3 or 4 for 5 ARGV's it will still search for them , and success if all were found. </span>
<span style="color: #666666; font-style: italic;">#     </span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Last edited  : 14 Oct 09 </span>
<span style="color: #666666; font-style: italic;"># Author    : Sam Abdelhamid</span>
<span style="color: #666666; font-style: italic;"># Version    : 1.0</span>
<span style="color: #666666; font-style: italic;"># #########################################################################</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#following lines only used for testing. </span>
<span style="color: #666666; font-style: italic;">#~ open F1,&quot;D:\\input.txt&quot; or die &quot;InputTextFile $!&quot;;</span>
<span style="color: #666666; font-style: italic;">#~ open F2,&quot;D:\\EP7NN.txt&quot; or die &quot;FIleToSearch $!&quot;;</span>
<span style="color: #666666; font-style: italic;">#~ my $maxLines = 25;</span>
<span style="color: #666666; font-style: italic;">##############</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$searchItemsCounter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lineFound</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#get the input file</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Enter the input filename path: &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">chomp</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$inFile</span> <span style="color: #339933;">=</span> <span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#convert slashes and escape them</span>
<span style="color: #0000ff;">$inFile</span><span style="color: #339933;">=~</span> <span style="color: #000066;">s</span><span style="color: #339933;">,/,</span>\\<span style="color: #339933;">,</span>g<span style="color: #339933;">;</span>
<span style="color: #000066;">open</span> F1<span style="color: #339933;">,</span><span style="color: #0000ff;">$inFile</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Could not open file $!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#get the file to search through</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Enter path of the file to search : &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">chomp</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$readFile</span> <span style="color: #339933;">=</span> <span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$readFile</span><span style="color: #339933;">=~</span> <span style="color: #000066;">s</span><span style="color: #339933;">,/,</span>\\<span style="color: #339933;">,</span>g<span style="color: #339933;">;</span>
<span style="color: #000066;">open</span> F2<span style="color: #339933;">,</span><span style="color: #0000ff;">$readFile</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Could not open file $!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Search over how many lines? : &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">chomp</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$maxLines</span> <span style="color: #339933;">=</span> <span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;F1&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                  <span style="color: #0000ff;">@ARG</span><span style="color: #339933;">=</span><span style="color: #000066;">map</span> <span style="color: #009966; font-style: italic;">qr/\Q$_\E/</span><span style="color: #339933;">,</span><span style="color: #000066;">split</span><span style="color: #339933;">;</span>
                  <span style="color: #0000ff;">$searchItemsCounter</span><span style="color: #339933;">++;</span>
                  <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;*** Search Item Line $searchItemsCounter *** <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                  <span style="color: #000066;">seek</span> F2<span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                  <span style="color: #b1b100;">my</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A2</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A3</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A4</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A5</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lineCounter</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;F2&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                                       <span style="color: #0000ff;">$.</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000ff;">$maxLines</span> <span style="color: #b1b100;">if</span> <span style="color: #009966; font-style: italic;">/$ARG[0]/</span><span style="color: #339933;">;</span>
                                       <span style="color: #0000ff;">$A1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A1</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[1]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                       <span style="color: #0000ff;">$A2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A2</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[2]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                       <span style="color: #0000ff;">$A3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A3</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[3]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                       <span style="color: #0000ff;">$A4</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A4</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[4]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                       <span style="color: #0000ff;">$A5</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A5</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[5]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                       <span style="color: #0000ff;">$A6</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A6</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[6]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                       <span style="color: #666666; font-style: italic;">#calculate the line that the first ARG was found on - Formula below....not as simple as getting the line number! </span>
                                       <span style="color: #0000ff;">$lineFound</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$lineCounter</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$maxLines</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$.</span> <span style="color: #cc66cc;">+1</span><span style="color: #339933;">;</span>
                                       <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> Found on line number $lineFound <span style="color: #000099; font-weight: bold;">\n</span> Found within $maxLines lines <span style="color: #000099; font-weight: bold;">\n</span> $ARG[0] <span style="color: #000099; font-weight: bold;">\n</span> $ARG[1] <span style="color: #000099; font-weight: bold;">\n</span> $ARG[2] <span style="color: #000099; font-weight: bold;">\n</span> $ARG[3] <span style="color: #000099; font-weight: bold;">\n</span> $ARG[4] <span style="color: #000099; font-weight: bold;">\n</span> $ARG[5] <span style="color: #000099; font-weight: bold;">\n</span>$ ARG[6] <span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">and</span> <span style="color: #000066;">seek</span> F2<span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$A1</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A2</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A3</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A4</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A5</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A6</span><span style="color: #339933;">;</span>
                                       <span style="color: #0000ff;">$lineCounter</span><span style="color: #339933;">++;</span>
                                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>UPDATE&#8230;</strong><br />
Ok, so we all know requirements change. And the slightest of changes can make hours of work for us &#8216;developers&#8217;. Often, these changes are only advised after the initial peice of work is completed and they realise that it does not do what they intended vs what they asked.<br />
So here is an enhancment to this my script. </p>
<p>1. Remove user interaction and place &#8220;lines to search over&#8221; and &#8220;File to search&#8221; as values in the input file<br />
2. Hardcode the input file -> it is now hardcode as input.txt and must be in the same dir as the Perl script<br />
3. Allow for up to 10 values to be searched<br />
4. Allow functionality to have one input file search in in multiple files -> As the &#8220;File to search&#8221; is a value in the input.txt file, this is possible.</p>
<p>The input file is in the following format</p>

<div class="wp_syntax"><div class="code"><pre class="text">LinesToSearch FileToSearch value1 value2 value3 value3 value5 value6 value7 value8 value9 value10</pre></div></div>

<p>It is space delimited, and the first 3 options are mandatory, that is, you must specify the Lines to search, the File to search in and at least 1 value to search for.</p>

<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;"># #########################################################################</span>
<span style="color: #666666; font-style: italic;">#Perl search multiple lines</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Usage    : find.pl</span>
<span style="color: #666666; font-style: italic;"># Options  : NONE - All options are entered via the input.txt file</span>
<span style="color: #666666; font-style: italic;">#    </span>
<span style="color: #666666; font-style: italic;">#     The script will search for values in a block of text. The values are parsed via an input file. </span>
<span style="color: #666666; font-style: italic;">#     the input file is called input.txt and must be in the same dir as this script. The input.txt format is as follows</span>
<span style="color: #666666; font-style: italic;">#     10 blah.txt searchValue1 searchValue2 searchValue3 ... searchValue10</span>
<span style="color: #666666; font-style: italic;">#     The first value (10) is the amount of lines in the block of text that all preceeding values should appear. If the searchValue(s) are</span>
<span style="color: #666666; font-style: italic;">#     not found in this block, the search reports nothing, which is a fail. If found, it will report what line it was found and is a pass. </span>
<span style="color: #666666; font-style: italic;">#     The second value (blah.txt) is the file in which you want this script to conduct the search. </span>
<span style="color: #666666; font-style: italic;">#     if on a windows box, use double slashes ie. c:\\windows\\\temp\\blah.txt </span>
<span style="color: #666666; font-style: italic;">#     if on a mainframe, single slashes suffice ie. /var/tmp/blah.txt or if placed in the same dir as this script, just the physical name is enough</span>
<span style="color: #666666; font-style: italic;">#     ie. blah.txt.</span>
<span style="color: #666666; font-style: italic;">#     </span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Last edited  : 15 Oct 09 </span>
<span style="color: #666666; font-style: italic;"># Author    : Sam Abdelhamid</span>
<span style="color: #666666; font-style: italic;"># Version    : 1.1</span>
<span style="color: #666666; font-style: italic;"># #########################################################################</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#counters used later</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$searchItemsCounter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lineFound</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#data to search input file, should be in same dir as perl script. </span>
<span style="color: #0000ff;">$data_file</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;input.txt&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>F1<span style="color: #339933;">,</span> <span style="color: #0000ff;">$data_file</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Could not open file!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#put data into array and assign to F1</span>
<span style="color: #0000ff;">@raw_data</span><span style="color: #339933;">=</span><span style="color: #009999;">&lt;F1&gt;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">#Split the data by spaces</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@raw_data</span><span style="color: #009900;">&#41;</span>
          <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">@ARG</span><span style="color: #339933;">=</span><span style="color: #000066;">split</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;">#Items to search for. Count of array minus 2 (as the first 2 inputs in the inputfile are Lines to search, and file to search, the remaining are values.</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$items</span> <span style="color: #339933;">=</span><span style="color: #000066;">scalar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@ARG</span><span style="color: #009900;">&#41;</span><span style="color: #cc66cc;">-2</span><span style="color: #339933;">;</span>
                  <span style="color: #666666; font-style: italic;">#Counts how many searches needs to take place by searchign the items in the array</span>
                  <span style="color: #0000ff;">$searchItemsCounter</span><span style="color: #339933;">++;</span>
                  <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;*** Search Item Line $searchItemsCounter *** <span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                  <span style="color: #666666; font-style: italic;">#print &quot;\n Items is $items \n&quot;;</span>
                  <span style="color: #000066;">open</span> F2<span style="color: #339933;">,</span><span style="color: #0000ff;">$ARG</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;FileToSearch $!&quot;</span><span style="color: #339933;">;</span>
                  <span style="color: #000066;">seek</span> F2<span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                  <span style="color: #666666; font-style: italic;">#Create some variables to use for later</span>
                  <span style="color: #b1b100;">my</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A2</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A3</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A4</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A5</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A6</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A7</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A8</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$A9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lineCounter</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                  <span style="color: #666666; font-style: italic;">#While there is a line in F2 (file to search) use the regex to search for the text, and evaluate later</span>
                  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;F2&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                                      <span style="color: #0000ff;">$.</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000ff;">$ARG</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">if</span> <span style="color: #009966; font-style: italic;">/$ARG[2]/</span><span style="color: #339933;">;</span>
                                      <span style="color: #0000ff;">$A0</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A0</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[2]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                      <span style="color: #0000ff;">$A1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A1</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[3]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                      <span style="color: #0000ff;">$A2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A2</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[4]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                      <span style="color: #0000ff;">$A3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A3</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[5]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                      <span style="color: #0000ff;">$A4</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A4</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[6]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                      <span style="color: #0000ff;">$A5</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A5</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[7]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                      <span style="color: #0000ff;">$A6</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A6</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[8]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                      <span style="color: #0000ff;">$A7</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A7</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[9]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                      <span style="color: #0000ff;">$A8</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A8</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[10]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                      <span style="color: #0000ff;">$A9</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$.</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A9</span> <span style="color: #339933;">||=</span> <span style="color: #009966; font-style: italic;">/$ARG[11]/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                      <span style="color: #666666; font-style: italic;">#calculate the line that the first ARG was found on - Formula below....not as simple as getting the line number! </span>
                                      <span style="color: #0000ff;">$lineFound</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$lineCounter</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$ARG</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span> <span style="color: #0000ff;">$.</span> <span style="color: #cc66cc;">+1</span><span style="color: #339933;">;</span>
                                      <span style="color: #666666; font-style: italic;">#If all values were found, print the output, if not,print nothing. </span>
                                      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$A0</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A1</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A2</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A3</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A4</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A5</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A6</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A7</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A8</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #0000ff;">$A9</span><span style="color: #009900;">&#41;</span>
                                        <span style="color: #009900;">&#123;</span><span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot; Searching for $items items <span style="color: #000099; font-weight: bold;">\n</span> Found $ARG[2] on line number $lineFound <span style="color: #000099; font-weight: bold;">\n</span> All items were found within $ARG[0] lines <span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> 
                                                  <span style="color: #b1b100;">and</span> <span style="color: #000066;">seek</span> F2<span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
                                       <span style="color: #666666; font-style: italic;">#increment line counter for display purposes</span>
                                     <span style="color: #0000ff;">$lineCounter</span><span style="color: #339933;">++;</span>
                                  <span style="color: #009900;">&#125;</span>
          <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here is a sample input file for the script above.</p>

<div class="wp_syntax"><div class="code"><pre class="text">10 EP7NN.txt 74900000216000510143633 036 000000000754 634 000000002300
10 EP7NN.txt 4900031000058217000 74940479216000510143633 036daec 000000000754 634 000000002300
10 EP7NN.txt 4940000087094009000 74940479216000510285988 036 000000150230 634 000000458420
20 EP7NN.txt 4900005278709499000 74940479216000510285988 036 000000150230 634 000000458420 5921 00000 TRAN ISS
20 EP7NN.txt 4900000000009499000 74940479216000510285988 036 000000150230 634 000000458420 5921 00000 TRAN ISSadf
20 D:\\scripts\\Watir\\EP7NN.txt 036 000000150230 634 000000458420
20 D:\\scripts\\Watir\\EP7NN.txt 4940525278709499000
12 D:\\scripts\\Watir\\EP7NN.txt 036 000000000754defe</pre></div></div>

<p>Enjoy! ..</p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=71</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>reformating vmstat/sar/iostat logs :: loadrunner analysis</title>
		<link>http://mishmashmoo.com/blog/?p=65</link>
		<comments>http://mishmashmoo.com/blog/?p=65#comments</comments>
		<pubDate>Sat, 19 Sep 2009 17:12:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=65</guid>
		<description><![CDATA[Quite often, I don’t get a read only ssh account to a server, so I can capture server metrics during runtime in loadrunner. This usually means I need to request the data to be sent to me after the test, which the sys admin will very easily do. The only problem here, is that a [...]]]></description>
			<content:encoded><![CDATA[<p>Quite often, I don’t get a read only ssh account to a server, so I can capture server metrics during runtime in loadrunner. This usually means I need to request the data to be sent to me after the test, which the sys admin will very easily do. The only problem here, is that a vmstat log is ugly, and difficult to read in raw text not to mention, had to analyse.<br />
Test managers are generally very busy, and want a report with pretty pictures, giving them a view on what was happening during the run. Loadrunner analysis is a great tool for displaying such data, and has an import ability, for such problems, but first, we must convert our vmstat/sar/iostat file into a format that is easily graph-able.<br />
<span id="more-65"></span><br />
Ruby and data manipulation go hand in hand, its quick, efficient, and very easy, so it only makes sense to script it up.<br />
With all that said, here is a nice way to get your data from a log to a CSV. You can then import into loadrunner analysis, or use excel to graph the data you require.<br />
I started with the scripts from my good friend &#038; talented performance tester Tim Koopmans, <a href="http://90kts.com/blog/2008/formatting-data-for-import-into-loadrunner-analysis/">here</a> and made some changes, to make it dump a file out instead of having to copy the data from the output pane.<br />
There is an <b>infile</b> and <b>outfile</b> parameter. Self explanatory, change them, run this, and you&#8217;re on your way! </p>
<p><strong>vmstat</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby">infile = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">'c:<span style="color:#000099;">\v</span>mstat.20090915.log'</span>
freq = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">5</span>
outfile = <span style="color:#996600;">'c:<span style="color:#000099;">\b</span>lah'</span>
stat = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">stat</span><span style="color:#006600; font-weight:bold;">&#40;</span>infile<span style="color:#006600; font-weight:bold;">&#41;</span>
now  = stat.<span style="color:#9900CC;">mtime</span>
t=<span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
lines=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">readlines</span><span style="color:#006600; font-weight:bold;">&#40;</span>infile<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">reverse_each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span>
	line.<span style="color:#CC0066; font-weight:bold;">chomp</span>
	<span style="color:#9966CC; font-weight:bold;">if</span> line.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>^\s<span style="color:#006600; font-weight:bold;">+</span>\d<span style="color:#006600; font-weight:bold;">+/</span>m<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">then</span>
        now  = now <span style="color:#006600; font-weight:bold;">-</span> freq
         date = <span style="color:#996600;">&quot;#{now.day}/#{now.month}/#{now.year}&quot;</span>
        time = <span style="color:#996600;">&quot;#{now.hour}:#{now.min}:#{now.sec}&quot;</span>
		data = line.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>^\s<span style="color:#006600; font-weight:bold;">+/</span>m,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>\s\t<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+/</span>m,<span style="color:#996600;">&quot;,&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>,$<span style="color:#006600; font-weight:bold;">/</span>m,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    lines<span style="color:#006600; font-weight:bold;">&lt;&lt;</span><span style="color:#996600;">&quot;#{date},#{time},#{data}&quot;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
lines.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>row<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>outfile<span style="color:#006600; font-weight:bold;">+</span>t.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;%m%d%Y_%H%M%S&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#996600;">&quot;.csv&quot;</span>,<span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>the_file<span style="color:#006600; font-weight:bold;">|</span>
  the_file.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;date,time,r,b,w,swap,free,re,mf,pi,po,fr,de,sr,m0,m1,m2,m1,in,sy,cs,us,sy,id&quot;</span>    
      the_file.<span style="color:#CC0066; font-weight:bold;">puts</span> lines                      
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>sar</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby">infile = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">'c:<span style="color:#000099;">\s</span>tatfiles<span style="color:#000099;">\2</span>26<span style="color:#000099;">\0</span>910290151__SAR.log'</span>
freq = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">5</span>
outfile = <span style="color:#996600;">'c:<span style="color:#000099;">\s</span>tatfiles<span style="color:#000099;">\2</span>26<span style="color:#000099;">\s</span>ar.csv'</span>
&nbsp;
stat = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">stat</span><span style="color:#006600; font-weight:bold;">&#40;</span>infile<span style="color:#006600; font-weight:bold;">&#41;</span>
now  = stat.<span style="color:#9900CC;">mtime</span>
t=<span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
lines=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">readlines</span><span style="color:#006600; font-weight:bold;">&#40;</span>infile<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span>
	line.<span style="color:#CC0066; font-weight:bold;">chomp</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> line.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>\d<span style="color:#006600; font-weight:bold;">+</span>\<span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+</span>\<span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+</span>$<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>m<span style="color:#006600; font-weight:bold;">&#41;</span>: <span style="color:#ff6633; font-weight:bold;">$date</span> = $<span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> line.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#40;</span>\d<span style="color:#006600; font-weight:bold;">+</span>:\d<span style="color:#006600; font-weight:bold;">+</span>:\d<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>m<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">then</span>
        time = $<span style="color:#006666;">1</span>
        <span style="color:#9966CC; font-weight:bold;">unless</span> line.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>usr<span style="color:#006600; font-weight:bold;">/</span>m<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">then</span>
            data = line.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+</span>:\d<span style="color:#006600; font-weight:bold;">+</span>:\d<span style="color:#006600; font-weight:bold;">+/</span>m,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>^\s<span style="color:#006600; font-weight:bold;">+/</span>m,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>\s\t<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+/</span>m,<span style="color:#996600;">&quot;,&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>,$<span style="color:#006600; font-weight:bold;">/</span>m,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
		    lines<span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;#{$date},#{time},#{data}&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
lines.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>row<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>outfile<span style="color:#006600; font-weight:bold;">+</span>t.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;%m%d%Y_%H%M%S&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#996600;">&quot;.csv&quot;</span>,<span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>the_file<span style="color:#006600; font-weight:bold;">|</span>
  the_file.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;date,time,%usr,%sys,%wio,%idle&quot;</span>
      the_file.<span style="color:#CC0066; font-weight:bold;">puts</span> lines
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>iostat</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby">infile = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">'c:<span style="color:#000099;">\s</span>tatfiles<span style="color:#000099;">\2</span>26<span style="color:#000099;">\0</span>910290151__IOSTAT.log'</span>
freq = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">5</span>
outfile = <span style="color:#996600;">'c:<span style="color:#000099;">\s</span>tatfiles<span style="color:#000099;">\2</span>26<span style="color:#000099;">\i</span>ostat.csv'</span>
&nbsp;
stat = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">stat</span><span style="color:#006600; font-weight:bold;">&#40;</span>infile<span style="color:#006600; font-weight:bold;">&#41;</span>
now  = stat.<span style="color:#9900CC;">mtime</span>
t=<span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
lines=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">readlines</span><span style="color:#006600; font-weight:bold;">&#40;</span>infile<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span>
	line.<span style="color:#CC0066; font-weight:bold;">chomp</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> line.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#40;</span>\d<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span>m<span style="color:#006600; font-weight:bold;">&#41;</span>: <span style="color:#ff6633; font-weight:bold;">$epoch</span> = $<span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> line.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>^\d<span style="color:#006600; font-weight:bold;">+</span>\.\d<span style="color:#006600; font-weight:bold;">+/</span>m<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">then</span>
        dtg = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">at</span><span style="color:#006600; font-weight:bold;">&#40;</span>$epoch.<span style="color:#9900CC;">to_i</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;%d/%m/%Y,%H:%M:%S&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> line.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>,<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>\w\d<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span>m<span style="color:#006600; font-weight:bold;">&#41;</span>: dvc = $<span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">end</span>
        line = line.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>,<span style="color:#006600; font-weight:bold;">&#91;</span>\w\d<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span>$<span style="color:#006600; font-weight:bold;">/</span>m,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
		lines<span style="color:#006600; font-weight:bold;">&lt;&lt;</span><span style="color:#996600;">&quot;#{dtg},#{dvc},#{line}&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> lines
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
lines.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>row<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>outfile<span style="color:#006600; font-weight:bold;">+</span>t.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;%m%d%Y_%H%M%S&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#996600;">&quot;.csv&quot;</span>,<span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>the_file<span style="color:#006600; font-weight:bold;">|</span>
  the_file.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;date,time,device,r/s,w/s,Mr/s,Mw/s,wait,actv,wsvc_t,asvc_t,%w,%b&quot;</span>
      the_file.<span style="color:#CC0066; font-weight:bold;">puts</span> lines
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=65</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>saving vugen paramaters into a file :: vugen</title>
		<link>http://mishmashmoo.com/blog/?p=61</link>
		<comments>http://mishmashmoo.com/blog/?p=61#comments</comments>
		<pubDate>Fri, 18 Sep 2009 04:52:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=61</guid>
		<description><![CDATA[Performance and load testing has many input requirements. The most important and difficult to obtain, is clean and valid input data. I find that it’s often harder to request for data, than it is to just make my own. Unless the data needs to be aged, or processed somewhat, then you are stuck at the [...]]]></description>
			<content:encoded><![CDATA[<p>Performance and load testing has many input requirements. The most important and difficult to obtain, is clean and valid input data. I find that it’s often harder to request for data, than it is to just make my own. Unless the data needs to be aged, or processed somewhat, then you are stuck at the back of the queue. So think not of vugen/loadrunner as only a performance testing tool, but a gateway to process information on the application at a rapid rate. This is why I favour vugen/loadrunner as a data creation tool.<br />
Once I set up my scripts they can often be reused throughout the lifespan of the project creating adhoc data when I need, quickly and rapidly. </p>
<p>Storing the data is something I&#8217;ve experimented with over the years, and have found that a mysql database is superior to store, validate, and call your from, all with a nice little wamp server, but more about that another time. If you want to just store your data in a CSV, text file, or any other format to your liking, you can do easily. I warn you, it’s clunky but it does work.<br />
<span id="more-61"></span><br />
Since vugen http/html is based on C, you can do allot with it. C is one of those languages that everyone knows, but requires allot of lines of code to do a simple task that my friend ruby can do in 2 lines or less.<br />
So if you have ever wanted to save your parameters from a web_reg_find just add something like this to your script.</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>filename<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;c:<span style="color: #000099; font-weight: bold;">\\</span>yourfile.txt&quot;</span>;
<span style="color: #666666; font-style: italic;">//Open the file with read access --some error handling is nice. </span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>file <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>filename, <span style="color: #ff0000;">&quot;a+&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">NULL</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
lr_error_message<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Cannot open %s&quot;</span>, filename<span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">-1</span>;
<span style="color: #009900;">&#125;</span>
fprintf<span style="color: #009900;">&#40;</span>file,<span style="color: #ff0000;">&quot;%s %s %s %s&quot;</span>,lr_eval_string<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;{value1}&quot;</span><span style="color: #009900;">&#41;</span>,<span style="color: #ff0000;">&quot;,&quot;</span>,lr_eval_string<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;{value2}&quot;</span><span style="color: #009900;">&#41;</span>,<span style="color: #ff0000;">&quot;,);
fprintf(file,&quot;</span>\n<span style="color: #ff0000;">&quot;);
fclose(file);
</span</pre></div></div>

<p>It’s really quite simple. Now the issue here is that you will have problems running this with multiple users, as you will get access violations with multiple users trying to access the same memory space &#8212; hence my clunky comment. The solution is to either run it with 1 user, which is fine, its only data creation and can run overnight, if the environment is available, If its not, you can paramatise the file name with vuserId, and save multiple copies of the file, one per vuser, and then combine them later.<br />
In this example, I&#8217;ve made a CSV file, and defined that 4 strings will follow (including the commas), then a new line, so the next iteration will be separated, and then finally close the file. Simple, easy, quick and dirty. </p>
<p>Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=61</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>loop/iterate through an ordinal array :: vugen</title>
		<link>http://mishmashmoo.com/blog/?p=57</link>
		<comments>http://mishmashmoo.com/blog/?p=57#comments</comments>
		<pubDate>Thu, 17 Sep 2009 19:00:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=57</guid>
		<description><![CDATA[When saving paramaters through the web_reg_save_param, the ord=all option is very useful in finding multiple instances of your desired item.
Generally you can work out which ordinal you want to use, and call your parameter later using {paramaterValue_15} for the 16th ordinal (starts at 0). But what if you want to use every single ordinal found?.
Why? [...]]]></description>
			<content:encoded><![CDATA[<p>When saving paramaters through the web_reg_save_param, the ord=all option is very useful in finding multiple instances of your desired item.<br />
Generally you can work out which ordinal you want to use, and call your parameter later using {paramaterValue_15} for the 16th ordinal (starts at 0). But what if you want to use every single ordinal found?.<br />
Why? Well, why not! &#8212; you could have a situation where every ordinal found is a value which is the trail of a url, and you want to navigate to each subsequent url that this page returned. Since the ORD is an array, we should be able to call it easily via paramaterValue[#], right?. Wrong&#8230;this simply doesn’t work in vugen, however with a little bit of funky C coding, the answer is quite simple.<br />
<span id="more-57"></span><br />
I won&#8217;t delve into the explaining too much, but basically, you&#8217;re looping through each item, assigning it to a new parameter, and then you can proceed with the rest of your action (don’t forget to move the last bracket in the for loop).</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #993333;">char</span> myString<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">20</span><span style="color: #009900;">&#93;</span>;
ItemNumCount <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>lr_eval_string<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;{AgencyId_count}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span>;i &lt;<span style="color: #339933;">=</span>ItemNumCount;i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			sprintf<span style="color: #009900;">&#40;</span>myString, <span style="color: #ff0000;">&quot;{AgencyId_%i}&quot;</span>, i<span style="color: #009900;">&#41;</span>;
			lr_save_string<span style="color: #009900;">&#40;</span>lr_eval_string<span style="color: #009900;">&#40;</span>myString<span style="color: #009900;">&#41;</span>, <span style="color: #ff0000;">&quot;Id&quot;</span><span style="color: #009900;">&#41;</span>;
			lr_message<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Name: %s&quot;</span>, lr_eval_string<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;{Id}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=57</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
