<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Scripting on bramp.net</title>
    <link>https://blog.bramp.net/</link>
    <description>Recent content in Scripting on bramp.net</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-GB</language>
    <lastBuildDate>Tue, 31 Aug 2010 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://blog.bramp.net/tags/scripting/" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Persec python script</title>
      <link>https://blog.bramp.net/post/2010/08/31/persec-python-script/</link>
      <pubDate>Tue, 31 Aug 2010 00:00:00 +0000</pubDate>
      
      <guid>https://blog.bramp.net/post/2010/08/31/persec-python-script/</guid>
      <description><p>A while ago I wrote a python script that does a similar job to GNU’s <a href="http://linux.die.net/man/1/watch">watch</a> command. You use it like so:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">./persec.py <span class="o">[</span>--interval<span class="o">=</span><span class="p">&amp;</span>lt<span class="p">;</span>n<span class="p">&amp;</span>gt<span class="p">;</span><span class="o">]</span> <span class="p">&amp;</span>lt<span class="p">;</span>command<span class="p">&amp;</span>gt<span class="p">;</span>
</span></span></code></pre></div><p>so for example</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">./persec.py ifconfig
</span></span></code></pre></div><p>Now in a similar way to watch, it executes the command every second, and highlights the differences between each execution. However, in addition to this it finds any numbers that have changed and works out the rate at which they are changing. So for example, ifconfig would typically output this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">usb0      Link encap:Ethernet  HWaddr 02:04:4b:00:d3:cf
</span></span><span class="line"><span class="cl">          inet addr:10.0.0.2  Bcast:10.0.0.255  Mask:255.255.255.0
</span></span><span class="line"><span class="cl">          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
</span></span><span class="line"><span class="cl">          RX packets:1017422291 errors:0 dropped:0 overruns:0 frame:0
</span></span><span class="line"><span class="cl">          TX packets:549382406 errors:0 dropped:0 overruns:0 carrier:0
</span></span><span class="line"><span class="cl">          collisions:0 txqueuelen:1000
</span></span><span class="line"><span class="cl">          RX bytes:1910704266 (1.9 GB)  TX bytes:1834667124 (1.8 GB)
</span></span></code></pre></div><p>but now outputs something like:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">usb0      Link encap:Ethernet  HWaddr 02:04:4b:00:d3:cf
</span></span><span class="line"><span class="cl">          inet addr:10.0.0.2  Bcast:10.0.0.255  Mask:255.255.255.0
</span></span><span class="line"><span class="cl">          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
</span></span><span class="line"><span class="cl">          RX packets:&lt;b&gt;2001/s&lt;/b&gt; errors:0 dropped:0 overruns:0 frame:0
</span></span><span class="line"><span class="cl">          TX packets:&lt;b&gt;2002/s&lt;/b&gt; errors:0 dropped:0 overruns:0 carrier:0
</span></span><span class="line"><span class="cl">          collisions:0 txqueuelen:1000
</span></span><span class="line"><span class="cl">          RX bytes:&lt;b&gt;168120/s&lt;/b&gt; (1.9 GB)  TX bytes:&lt;b&gt;217144/s&lt;/b&gt; (1.8 GB)
</span></span></code></pre></div><p>Notice the per second (/s) values for RX/TX packets and RX/TX bytes. I have found this quite useful many times in the past, on commands such as:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">./persec.py cat /proc/interrupts
</span></span><span class="line"><span class="cl">./persec.py df
</span></span><span class="line"><span class="cl">./persec.py ls -l somefile
</span></span></code></pre></div><p><a href="https://raw.githubusercontent.com/bramp/handy-tools/master/persec.py">Download version 1.1</a> or <a href="https://github.com/bramp/handy-tools/blob/master/persec.py">View on Github</a></p>
</description>
    </item>
    
  </channel>
</rss>
