<?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>Blog.Project13.pl &#187; bash</title>
	<atom:link href="http://www.blog.project13.pl/index.php/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blog.project13.pl</link>
	<description>The Blog of a Coder</description>
	<lastBuildDate>Sun, 05 Feb 2012 02:28:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[terminal heroes] Display git branch in shell prompt (PS1)</title>
		<link>http://www.blog.project13.pl/index.php/fun/1198/terminal-heroes-display-git-branch-in-shell-prompt-ps1/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/1198/terminal-heroes-display-git-branch-in-shell-prompt-ps1/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 22:29:01 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[branch]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[prompt]]></category>
		<category><![CDATA[ps1]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1198</guid>
		<description><![CDATA[I don&#8217;t think I&#8217;ve blogged about this but I&#8217;ve seen this sometime ago and now decided to add it to my .bashrc for good. It&#8217;s a simple trick to make an awesome PS1 shell prompt, displaying the branch you are currently on (if you&#8217;re in a git versioned directory). Not that I&#8217;m forgetting what branch [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t think I&#8217;ve blogged about this but I&#8217;ve seen this sometime ago and now decided to add it to my .bashrc for good. It&#8217;s a simple trick to make an awesome PS1 shell prompt, displaying the branch you are currently on (if you&#8217;re in a git versioned directory). Not that I&#8217;m forgetting what branch I&#8217;m on, but I hope it&#8217;ll make me create more branches more often and never &#8220;just work on master&#8221; :-)</p>
<p><a href="http://www.blog.project13.pl/wp-content/uploads/2011/02/awesome-git-branch-in-shell.png"><img src="http://www.blog.project13.pl/wp-content/uploads/2011/02/awesome-git-branch-in-shell.png" alt="" title="awesome-git-branch-in-shell" width="530" class="aligncenter size-full wp-image-1211" /></a></p>
<p>The code comes from <a href="http://arnorehn.de/cgi-bin/weblog_basic/index.php?p=34" onclick="urchinTracker('/outgoing/arnorehn.de/cgi-bin/weblog_basic/index.php?p=34&amp;referer=');">http://arnorehn.de/cgi-bin/weblog_basic/index.php?p=34</a> so big kudos too him :-)</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1"><span class="co0"># in your ~/.bashrc for example</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alias</span> <span class="re2">gitka=</span><span class="st0">&#39;gitk &#8211;all&#39;</span> <span class="co0">#unrelated to this post, but very useful :-)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">function</span> formattedGitBranch <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re2">_branch=</span><span class="st0">&quot;$(git branch 2&gt;/dev/null | sed -e &quot;</span><span class="sy0">/</span>^\s<span class="sy0">/</span>d<span class="st0">&quot; -e &quot;</span>s<span class="sy0">/</span>^\<span class="sy0">*</span>\s<span class="sy0">//</span><span class="st0">&quot;)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">test</span> -n <span class="st0">&quot;$_branch&quot;</span> <span class="sy0">&amp;&amp;</span> <span class="kw3">echo</span> -e <span class="st0">&quot; @<span class="es0">\e</span>[0;32m $_branch&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#export PS1=&quot;\u@\h \W \[\e[m\]\$(formattedGitBranch) \[\e[1;32m\]\$ \[\e[m\]\[\e[0m\]&quot; </span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">export</span> <span class="re2">PS1=</span><span class="st0">&quot;<span class="es0">\u</span>@<span class="es0">\h</span> <span class="es0">\W</span><span class="es0">\[</span><span class="es0">\e</span>[m<span class="es0">\]</span><span class="es0">\$</span>(formattedGitBranch)<span class="es0">\[</span><span class="es0">\e</span>[0m<span class="es0">\]</span> <span class="es0">\$</span> &quot;</span></div>
</li>
</ol>
</div>
<p>Cheers and <b>happy hacking</b>!</p>
<p>PS: I&#8217;m waiting for my T-shirt and stickers (for training participants) to arrive from github. I&#8217;d love they make it in time for <a href="http://www.sfi.org.pl" onclick="urchinTracker('/outgoing/www.sfi.org.pl?referer=');">SFI</a> but I&#8217;m not sure if it&#8217;s even possible hmmm&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/1198/terminal-heroes-display-git-branch-in-shell-prompt-ps1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>G73 keyboard backlight scripts</title>
		<link>http://www.blog.project13.pl/index.php/fun/1163/g73-keayboard-backlight-scripts/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/1163/g73-keayboard-backlight-scripts/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 19:09:42 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[fsf]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[notebook]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1163</guid>
		<description><![CDATA[I&#8217;ve upgraded my desktop and laptop last week. By &#8220;and&#8221; I mean that I&#8217;ve bought an desktop replacement class notebook &#8211; an Asus G73 series. Amongst many nice parts it has I&#8217;m very happy about the harddrives &#8211; Seagate Momentus XT, click the link to see an very interesting benchmark of it. Anyways, that&#8217;s not [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve upgraded my desktop and laptop last week. By &#8220;and&#8221; I mean that I&#8217;ve bought an desktop replacement class notebook &#8211; an <strong>Asus G73 </strong>series. Amongst many nice parts it has I&#8217;m very happy about the harddrives &#8211; <a href="http://www.tomshardware.com/reviews/seagate-momentus-xt-hybrid-hard-drive-ssd,2638.html" onclick="urchinTracker('/outgoing/www.tomshardware.com/reviews/seagate-momentus-xt-hybrid-hard-drive-ssd_2638.html?referer=');">Seagate Momentus XT</a>, click the link to see an very interesting benchmark of it. Anyways, that&#8217;s not what this post should be about.</p>
<p>The G73 has an backlit keyboard, which may come in handy while late night coding without lights on as I like to code sometimes. (I&#8217;m using a X6 Sidewinder, even with this Notebook so it&#8217;s not like it&#8217;s keyboard matters to me most of the time ;-)) As usual with such &#8220;super cool addons&#8221; the funtion keys regulating the keyboard backlight seemed to only work on Windows &#8211; which I&#8217;m only using for gaming (but rarely) and testing if the software I happened to write runs ok on it. Anyways, turns out that the keyboard does really well integrate with linux, and you just need a few simple commands to use it, I&#8217;ve made them available on github :-)</p>
<p><a href="https://github.com/ktoso/g73-keyboard-backlight-sh/" onclick="urchinTracker('/outgoing/github.com/ktoso/g73-keyboard-backlight-sh/?referer=');">https://github.com/ktoso/<strong>g73-keyboard-backlight-sh</strong></a> &lt;- Go here to check it out :-)</p>
<div class="geshi no markdown">
<div class="head">Asus G73 Keyboard Backlight GNU/Linux Scripts</div>
<ol>
<li class="li1">
<div class="de1">=============================================
</div>
</li>
<li class="li1">
<div class="de1">To enable the `Fn + F3` and `Fn + F4` shortcuts to work under linux and really
</div>
</li>
<li class="li1">
<div class="de1">manipulate the backlight brighntess on your *Asus G73* series notebook, follow theese simple steps:
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">1. Clone this repository to your home directory (or wherever you want to, I&#39;ll do this example for ~/ for simplicity)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;cd
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;git clone git://github.com/ktoso/g73-keyboard-backlight-sh.git g73
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;
</div>
</li>
<li class="li1">
<div class="de1">2. Make sure all scripts are marked executable:
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;cd g73
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;chmod +x *.sh
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">3. Take a look at these scripts to make sure you trust them, why? Because they&#39;ll need root access,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;without asking for the password. Now we&#39;ll add these scripts to allow `sudo`to run them without
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;asking for any password:
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;su -c &#39;visudo&#39; # or &#39;sudo visudo&#39; if you&#39;re a sudoer (on ubuntu etc)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;There just add the following lines at the end of this file (or similar, with the script names etc).
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;Of course, replace `ktoso` and `/home/ktoso/` with your *username* and *your home directory*.
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;## allow running keyboard backlight scripts
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;ktoso ALL=(ALL) NOPASSWD:/home/ktoso/g73/*
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">4. Now all that&#39;s left is to setup the key bindings for the scripts. If you&#39;re on KDE4, just go to
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;*System Settings -&amp;gt; Shortcuts and Gestures -&amp;gt; Custom Shortcuts* and *edit -&amp;gt; import&#8230;* the file **~/g73/g73_keyboard.khotkeys**
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; which contains ready keybindings for these scripts.
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Now you may use `Fn + F3` to make the keyboard backlight shine **less**, and the `Fn + F4` combination to make it shine **more**.</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/1163/g73-keayboard-backlight-scripts/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Terminal Heroes 8: Memory usage scripts</title>
		<link>http://www.blog.project13.pl/index.php/coding/442/memory-usage-scripts/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/442/memory-usage-scripts/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 10:54:21 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[gnu/linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=442</guid>
		<description><![CDATA[I have a low-memory VPS running online and thus always have to worry about what uses how much memory&#8230; Of course top and my favorite htop are very good tools to check this, but sometimes I just want to get a super simple report if I&#8217;m overusing memory or not yet. The bellow scripts (most [...]]]></description>
			<content:encoded><![CDATA[<p>I have a low-memory VPS running online and thus always have to worry about what uses how much memory&#8230; Of course top and my favorite <strong>htop</strong> are very good tools to check this, but sometimes I just want to get a super simple report if I&#8217;m overusing memory or not yet. The bellow scripts (most of them was found online or hacked up from multiple scripts to fit my needs) print simple yet very readable memory usage information.</p>
<h2>memused</h2>
<div class="geshi no bash">
<div class="head">#!/bin/bash</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#if [ $1 = &#39;&#39;]; then</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#    ps auxf | awk &#39;{sum=sum+$6}; END {print sum/1024}&#39;;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#else</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#    ps auxf | grep $1 | awk &#39;{sum=sum+$6}; END {print sum/1024}&#39;;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#fi</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re2">bean=</span>`<span class="kw2">cat</span> <span class="sy0">/</span>proc<span class="sy0">/</span>user_beancounters` <span class="re2">guar=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$bean&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> vmguar <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $4;}&#39;</span>` <span class="re2">burst=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$bean&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> privvm <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $5;}&#39;</span>` <span class="re2">priv=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$bean&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> privvm <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $2;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">total=</span>guar<span class="sy0">/</span><span class="nu0">256</span> <span class="kw3">let</span> <span class="re2">used=</span>priv<span class="sy0">/</span><span class="nu0">256</span> <span class="kw3">let</span> <span class="re2">burst=</span>burst<span class="sy0">/</span><span class="nu0">256</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;VPS memory usage:&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;Used: $used MB&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;Total: $total MB&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;Burstable to: $burst MB&quot;</span></div>
</li>
</ol>
</div>
<p>Sample output:<br />
<code>VPS memory usage:<br />
Used: 296 MB<br />
Total: 256 MB<br />
Burstable to: 512 MB</code></p>
<h2>memfree</h2>
<div class="geshi no bash">
<div class="head">#!/bin/bash</div>
<ol>
<li class="li1">
<div class="de1"><span class="co0">#</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># Revised 02-Feb-2007: include kernel memory (kmemsize) in &#39;used&#39; calculation</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># and show percentages in output.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">BEAN=</span>`<span class="kw2">cat</span> <span class="sy0">/</span>proc<span class="sy0">/</span>user_beancounters`</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">GUAR=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$BEAN&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> vmguar <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $4;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">PRIV=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$BEAN&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> privvm <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $2;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">KMEM=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$BEAN&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> kmem <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $3;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">TOTL=</span><span class="re1">$GUAR</span><span class="sy0">/</span><span class="nu0">256</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">KMMB=</span><span class="re1">$KMEM</span><span class="sy0">/</span><span class="nu0">1048576</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">PVMB=</span><span class="re1">$PRIV</span><span class="sy0">/</span><span class="nu0">256</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">USED=</span><span class="re1">$KMMB</span>+<span class="re1">$PVMB</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">FREE=</span><span class="re1">$TOTL</span>-<span class="re1">$USED</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="st0">&quot;$FREE&quot;</span> -gt <span class="st0">&quot;0&quot;</span> <span class="br0">&#93;</span>; <span class="kw1">then</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> <span class="re2">UPER=</span><span class="re1">$USED</span><span class="sy0">*</span><span class="nu0">100</span><span class="sy0">/</span><span class="re1">$TOTL</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> <span class="re2">FPER=</span><span class="nu0">100</span>-<span class="re1">$UPER</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> <span class="re2">UPER=</span><span class="st0">&quot;100&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> <span class="re2">FPER=</span><span class="st0">&quot;0&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">fi</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;VPS Memory:&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot; Total: $TOTL mb Used: $USED mb (${UPER}%) Free: $FREE mb (${FPER}%)&quot;</span></div>
</li>
</ol>
</div>
<p>Sample output:<br />
<code>VPS Memory:<br />
Total: 256 mb Used: 302 mb (100%) Free: -46 mb (0%)</code></p>
<h2>memheld</h2>
<div class="geshi no bash">
<div class="head">#!/bin/bash</div>
<ol>
<li class="li1">
<div class="de1"><span class="kw2">grep</span> oomguarpages <span class="sy0">/</span>proc<span class="sy0">/</span>user_beancounters <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{s=$2;t=$3;u=$4; {print &quot;VPS Memory Usage<span class="es0">\n</span>Current Held: &quot; s/256 &quot;MB<span class="es0">\n</span>Max Held: &quot; t/256 &quot;MB<span class="es0">\n</span>Barrier: &quot;u/256&quot;MB&quot; }}&#39;</span></div>
</li>
</ol>
</div>
<p>Sample output:<br />
<code>VPS Memory Usage<br />
Current Held: 160.832MB<br />
Max Held: 294.605MB<br />
Barrier: 256MB</code></p>
<h2>memps</h2>
<div class="geshi no bash">
<div class="head">#!/bin/bash</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;ps axo pmem,pcpu,comm | sort&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">ps</span> axo pmem,pcpu,<span class="kw2">comm</span> <span class="sy0">|</span> <span class="kw2">sort</span></div>
</li>
</ol>
</div>
<p>Sample output:<br />
<code>ps axo pmem,pcpu,comm | sort<br />
0.0  0.0 script<br />
0.0  0.0 script<br />
0.1  0.0 init<br />
#...<br />
2.2  0.0 httpd<br />
4.0  0.0 mysqld<br />
7.3  0.0 httpd<br />
8.0  0.0 httpd<br />
%MEM %CPU COMMAND</code></p>
<h2>memprivmpages</h2>
<div class="geshi no bash">
<div class="head">#!/bin/bash</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">beans=</span>`<span class="kw2">cat</span> <span class="sy0">/</span>proc<span class="sy0">/</span>user_beancounters <span class="sy0">|</span> <span class="kw2">grep</span> priv`</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">max=</span>`<span class="kw3">echo</span> <span class="re1">$beans</span> <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $4;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">use=</span>`<span class="kw3">echo</span> <span class="re1">$beans</span> <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $2;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="st0">&quot;per=$use*100/$max&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="st0">&quot;mb=$use/256&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="st0">&quot;mmb=$max/256&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;privvmpages usage: $mb MB ($per% of $mmb)&quot;</span></div>
</li>
</ol>
</div>
<p>Sample output:<br />
<code>privvmpages usage: 296 MB (57% of 512)</code><br />
For those wondering, yes I do have memory usage <em>above &#8220;100%&#8221; </em>in the output of some of these scripts, and it&#8217;s partially true. A VPS does usually have some guaranteed memory, and some &#8220;burstable&#8221; &#8211; so you can use more than just the guaranteed memory for some period of time. On the mashine I ran this I have 256 guaranteed and a &#8220;total&#8221; of 512MB &#8211; including the burstable memory.</p>
<p>If you like any of these, feel free to use them. I use them by creating a scripts directory and adding it to the PATH, so I can simply invoke them from anywhere.</p>
<p>PS: For more <strong>detailed memory usage information</strong> (as graphs etc), I&#8217;m using <a href="http://munin.projects.linpro.no/" onclick="urchinTracker('/outgoing/munin.projects.linpro.no/?referer=');"><strong>Munin</strong></a> and really recommend it. The graphs it draws are really nice, and it <strong>doesn&#8217;t</strong> inflict heavy load on the server, and it can <strong>monitor remote hosts</strong> if needed!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/442/memory-usage-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kill only Tomcat</title>
		<link>http://www.blog.project13.pl/index.php/coding/422/easy-way-to-kill-tomcat/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/422/easy-way-to-kill-tomcat/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 22:14:47 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=422</guid>
		<description><![CDATA[There is sometimes the need to kill some JVM, I usually use &#8220;killall java&#8221; and that works fine as long as that&#8217;s in fact what I want &#8211; kill ALL. But let&#8217;s say i just want to kill Tomcat and not my IDE? The below method works quite well in such an situation: [ktoso@homunculus ~]$ [...]]]></description>
			<content:encoded><![CDATA[<p>There is sometimes the need to kill some JVM, I usually use &#8220;killall java&#8221; and that works fine as long as that&#8217;s in fact what I want &#8211; kill ALL. But let&#8217;s say i just want to kill Tomcat and not my IDE? The below method works quite well in such an situation:</p>
<div class="geshi no bash">
<div class="head">[ktoso@homunculus ~]$ sudo netstat -lpn | grep 8080</div>
<ol>
<li class="li1">
<div class="de1">tcp &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">0</span> &nbsp; &nbsp; &nbsp;<span class="nu0">0</span> :::<span class="nu0">8080</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :::<span class="sy0">*</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LISTEN &nbsp; &nbsp; &nbsp;<span class="nu0">18525</span><span class="sy0">/</span>java</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ktoso<span class="sy0">@</span>homunculus ~<span class="br0">&#93;</span>$ <span class="kw2">kill</span> <span class="nu0">18525</span> <span class="co0"># you might need to add -9 here (SIGKILL)</span></div>
</li>
</ol>
</div>
<p>A quickly hacked up version of an simple shell script to kill this tomcat could look like (I still suck at awk&#8230;):</p>
<div class="geshi no bash">
<div class="head">#!/bin/sh</div>
<ol>
<li class="li1">
<div class="de1"><span class="kw2">kill</span> <span class="nu0">-9</span> `<span class="kw2">netstat</span> -lpn <span class="sy0">|</span> <span class="kw2">grep</span> <span class="nu0">8080</span> <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{print $7}&#39;</span> <span class="sy0">|</span> <span class="kw2">awk</span> -F<span class="sy0">/</span> <span class="st0">&#39;{print $1}&#39;</span>`</div>
</li>
</ol>
</div>
<p>The above obviously sux, as we&#8217;re using two awk commands after another&#8230; Ans also in the above examples, I&#8217;ve assumed that tomcat is listening on 8080, this may not always be the case, since with mod_proxy_ajp, there is no need fot it to listen on it&#8217;s default port and just the one to communicate by AJP. Let&#8217;s use it&#8217;s name to find it&#8217;s PID, we&#8217;ll use ps and grep and awk &#8211; life is simple with them. :-)<br />
Here&#8217;s the final version of this command: </p>
<div class="geshi no bash">
<div class="head">#!/bin/sh</div>
<ol>
<li class="li1">
<div class="de1"><span class="kw2">kill</span> <span class="nu0">-9</span> `<span class="kw2">ps</span> aux <span class="sy0">|</span> <span class="kw2">grep</span> catalina <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{print $2}&#39;</span>`</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/422/easy-way-to-kill-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AWK and multiple lines from shell command</title>
		<link>http://www.blog.project13.pl/index.php/coding/274/awk-and-multiple-lines-from-shell-command/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/274/awk-and-multiple-lines-from-shell-command/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 15:11:16 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=274</guid>
		<description><![CDATA[Let&#8217;s say you want to read the ps output inside an AWK script, it&#8217;s not so simple since system returns an exit code and not the string you want &#8211; it&#8217;s being sent to stdout, here is a simple trick to read multiple lines from a shell command inside awk: awk 'BEGIN{while ("ps aux" &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you want to read the ps output inside an AWK script, it&#8217;s not so simple since system returns an exit code and not the string you want &#8211; it&#8217;s being sent to stdout, here is a simple trick to read multiple lines from a shell command inside awk:<br />
<code>awk 'BEGIN{while ("ps aux" | getline){ print "test " $1 " test"}}' /dev/null | more</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/274/awk-and-multiple-lines-from-shell-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Terminal Heroes &#8211; 6 &#8211; Track X events</title>
		<link>http://www.blog.project13.pl/index.php/fun/236/terminal-heroes-6-track-x-events/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/236/terminal-heroes-6-track-x-events/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 22:53:33 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command line fu]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[gnu/linux]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=236</guid>
		<description><![CDATA[Another Command Line Fu oneliner I&#8217;ve sumbited today: #show X window events in chosen window $ xev -id `xwininfo &#124; grep &#39;Window id&#39; &#124; awk &#39;{print $4}&#39;` EnterNotify event, serial 13, synthetic NO, window 0&#215;6400053, &#160; &#160; root 0x13c, subw 0x640005b, time 42431610, &#40;367,0&#41;, root:&#40;369,63&#41;, &#160; &#160; mode NotifyNormal, detail NotifyVirtual, same_screen YES, &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Another Command Line Fu oneliner I&#8217;ve sumbited today:</p>
<div class="geshi no bash">
<div class="head">#show X window events in chosen window</div>
<ol>
<li class="li1">
<div class="de1">$ xev -<span class="kw2">id</span> `xwininfo <span class="sy0">|</span> <span class="kw2">grep</span> <span class="st0">&#39;Window id&#39;</span> <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{print $4}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1">EnterNotify event, serial <span class="nu0">13</span>, synthetic NO, window 0&#215;6400053,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; root 0x13c, subw 0x640005b, <span class="kw1">time</span> <span class="nu0">42431610</span>, <span class="br0">&#40;</span><span class="nu0">367</span>,<span class="nu0">0</span><span class="br0">&#41;</span>, root:<span class="br0">&#40;</span><span class="nu0">369</span>,<span class="nu0">63</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; mode NotifyNormal, detail NotifyVirtual, same_screen YES,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; focus NO, state <span class="nu0">16</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">MotionNotify event, serial <span class="nu0">13</span>, synthetic NO, window 0&#215;6400053,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; root 0x13c, subw 0x640005b, <span class="kw1">time</span> <span class="nu0">42431610</span>, <span class="br0">&#40;</span><span class="nu0">367</span>,<span class="nu0">0</span><span class="br0">&#41;</span>, root:<span class="br0">&#40;</span><span class="nu0">369</span>,<span class="nu0">63</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; state 0&#215;10, is_hint <span class="nu0">0</span>, same_screen YES</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">MotionNotify event, serial <span class="nu0">13</span>, synthetic NO, window 0&#215;6400053,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; root 0x13c, subw 0x640005b, <span class="kw1">time</span> <span class="nu0">42431618</span>, <span class="br0">&#40;</span><span class="nu0">366</span>,<span class="nu0">0</span><span class="br0">&#41;</span>, root:<span class="br0">&#40;</span><span class="nu0">368</span>,<span class="nu0">63</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; state 0&#215;10, is_hint <span class="nu0">0</span>, same_screen YES</div>
</li>
</ol>
</div>
<p>After executing this, click on a window you want to track X Window events in. You could &#8220;read&#8221; this command like this: &#8220;<em>xev will track events in the window with the following -id, which we get by greping window information obtained by xwininfo</em>&#8221; :-)</p>
<p>Ok, but why did I need such weird information? Well, I wanted to make a simple video showing vis, a vim plugin etc. But as it is always in vim, keypresses are essential &#8211; so I wanted to &#8220;show what i type&#8221; bigger :-) I&#8217;ll post it really soon btw&#8230; :-)</p>
<p>The command was <a href="http://www.commandlinefu.com/commands/view/3547/track-x-window-events-in-chosen-window#comment" onclick="urchinTracker('/outgoing/www.commandlinefu.com/commands/view/3547/track-x-window-events-in-chosen-window_comment?referer=');">posted on commandlinefu</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/236/terminal-heroes-6-track-x-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Terminal Heroes &#8211; 4 &#8211; regexpias lair</title>
		<link>http://www.blog.project13.pl/index.php/fun/176/terminal-heroes-4-regexpias-lair/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/176/terminal-heroes-4-regexpias-lair/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 00:24:11 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[gnu/linux]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=176</guid>
		<description><![CDATA[Let&#8217;s drop a little humor in this time&#8230; You, brave Terminal Hero, shall kill -9 the daemon that has hidden itself in one of those files! We don&#8217;t know in which file you can find it though! We&#8217;re running out of time! The kingdom of GNU will be rm -rf&#8216;d if you won&#8217;t make it [...]]]></description>
			<content:encoded><![CDATA[<p><em>Let&#8217;s drop a little humor in this time&#8230; </em></p>
<p>You, brave <strong>Terminal</strong> Hero, shall <strong>kill -9</strong> the <strong>daemon</strong> that has hidden itself in one of those files! We don&#8217;t know in <strong>which</strong> file you can <strong>find</strong> it though! We&#8217;re running out of <strong>time</strong>! The kingdom of <strong>GNU</strong> will be <strong>rm -rf</strong>&#8216;d if you won&#8217;t <strong>make</strong> it in time!!! Luckily as a <strong>level 99 human root</strong>, have all the <strong>tools</strong> to <strong>find</strong> and ex<strong>term</strong>inate the dragon in no time! So let&#8217;s get <strong>grep</strong>ing.</p>
<div class="geshi no bash">
<div class="head">[ktoso@lairs ~]$ ls</div>
<ol>
<li class="li1">
<div class="de1">lair1 lair2 lair3 &#8230;&#8230;. lair1336</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ktoso<span class="sy0">@</span>lairs ~<span class="br0">&#93;</span>$ <span class="kw2">ls</span> -l <span class="sy0">|</span> <span class="kw2">wc</span> -l</div>
</li>
<li class="li1">
<div class="de1"><span class="nu0">1337</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ktoso<span class="sy0">@</span>lairs ~<span class="br0">&#93;</span>$ <span class="kw2">find</span> . -<span class="kw3">exec</span> <span class="kw2">grep</span> <span class="st0">&quot;Regexpia&quot;</span> <span class="st0">&#39;{}&#39;</span> \; -print</div>
</li>
<li class="li1">
<div class="de1">Regexpia is <span class="kw1">in</span> this <span class="kw2">file</span></div>
</li>
<li class="li1">
<div class="de1">.<span class="sy0">/</span>lair1270</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ktoso<span class="sy0">@</span>lairs ~<span class="br0">&#93;</span>$ kill_dragon_inside lair1270</div>
</li>
</ol>
</div>
<p>Ok, enough joking&#8230;This post is all about this one-liner:<code>find . -exec grep "Onyxia" '{}' \; -print</code><br />
It allows you to search all files (including sub directories) for the ones with the specified string inside them. It proved helpful to me as i had to get one *.php file from a <strong>photorec</strong> recovered bunch of files (some thousands of them&#8230;)&#8230; </p>
<p>Hope you had as much fun reading this as I had posting, and also that it might prove usefull to you. I found this on snipplr by the way, I really recommend this website!</p>
<p><em>PS: The title just sounds too awesome i think&#8230; If you didn&#8217;t get it, it&#8217;s about <a href="http://www.wowwiki.com/Onyxia" target="_blank" onclick="urchinTracker('/outgoing/www.wowwiki.com/Onyxia?referer=');">Onyxia&#8217;s Lair</a> from World of Warcraft :-)<br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/176/terminal-heroes-4-regexpias-lair/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Terminal Heroes &#8211; 3 &#8211; ^^ typo fixing</title>
		<link>http://www.blog.project13.pl/index.php/coding/178/terminal-heroes-3-typo-fixing/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/178/terminal-heroes-3-typo-fixing/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 03:04:45 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[gnu/linux]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=178</guid>
		<description><![CDATA[A great bash feature I just discovered is the &#8220;^blabla^bla&#8221; command (is it a &#8220;command&#8221; by the way..?) If typing stuff quickly by hand, typing mistakes (typos) happen&#8230; And it&#8217;s not really fast to fix them by using UP ARROW and then fixing the command by &#8220;hand&#8221;&#8230; A better, quicker way to do this is [...]]]></description>
			<content:encoded><![CDATA[<p>A great <strong>bash</strong> feature I just discovered is the &#8220;^blabla^bla&#8221; command <em>(is it a &#8220;command&#8221; by the way..?)</em> If typing stuff quickly by hand, typing mistakes (typos) happen&#8230; And it&#8217;s not really fast to fix them by using UP ARROW and then fixing the command by &#8220;hand&#8221;&#8230; A better, quicker way to do this is the ^^ I mentioned, it works like this:<code>[ktoso@homunculus /]# cd /home/ktozo<br />
-bash: cd: /home/ktozo: Nie ma takiego pliku ani katalogu<br />
[ktoso@homunculus /]# ^zo^so<br />
cd /home/ktoso<br />
[ktoso@homunculus ~]#<br />
</code>So it&#8217;s basically a simple <em>&#8220;replace and run&#8221;</em> command&#8230; :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/178/terminal-heroes-3-typo-fixing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

