<?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>BASH Cures Cancer &#187; tools</title>
	<atom:link href="http://bashcurescancer.com/category/tools/feed" rel="self" type="application/rss+xml" />
	<link>http://bashcurescancer.com</link>
	<description>Learn the UNIX/Linux command line</description>
	<lastBuildDate>Tue, 25 Oct 2011 18:09:07 +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>The best in command line xml: XMLStarlet</title>
		<link>http://bashcurescancer.com/the-best-in-command-line-xml-xmlstarlet.html</link>
		<comments>http://bashcurescancer.com/the-best-in-command-line-xml-xmlstarlet.html#comments</comments>
		<pubDate>Tue, 24 Jun 2008 04:32:48 +0000</pubDate>
		<dc:creator>Brock Noland</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://bashcurescancer.com/?p=151</guid>
		<description><![CDATA[Quite some time ago I wrote about using xsltproc to process xml on the command line. Thank fully someone pointed out XMLStarlet.  I now use XMLStarlet almost every day.  I work with a variety of REST based API&#8217;s gather information. XMLStartlet along with a simple for loop or xargs gives you an exceedingly powerful set [...]]]></description>
			<content:encoded><![CDATA[<p>Quite some time ago I wrote about using xsltproc to process xml on the command line. Thank fully someone pointed out <a href="http://xmlstar.sourceforge.net/">XMLStarlet</a>.  I now use XMLStarlet almost every day.  I work with a variety of REST based API&#8217;s gather information. XMLStartlet along with a simple for loop or xargs gives you an exceedingly powerful set of tools.</p>
<p>Here is a quick introduction into the power of XMLStarlet. This is just a teaser as I cannot share the data I work with. However, you should be able to see the power of this tool.</p>
<p>All the links from my RSS feed:</p>
<pre>$ curl -s 'http://bashcurescancer.com/rss/' | xml sel -t -m '//link' -v '.' -n

http://bashcurescancer.com</pre>
<pre>http://bashcurescancer.com/processing-xml-on-the-command-line.html

http://bashcurescancer.com/do-not-close-stderr.html</pre>
<pre>http://bashcurescancer.com/prepend-to-a-file-with-sponge-from-moreutils.html</pre>
<pre>http://bashcurescancer.com/bug-in-curl-is-fixed.html</pre>
<pre>http://bashcurescancer.com/using-kill-to-see-if-a-process-is-alive.html</pre>
<pre>http://bashcurescancer.com/performance-testing-with-curl.html</pre>
<pre>http://bashcurescancer.com/new-command-prepend.html</pre>
<pre>http://bashcurescancer.com/shell-function-which-webserver-does-that-site-run.html</pre>
<pre>http://bashcurescancer.com/exposing-command-line-programs-as-web-services.html

http://bashcurescancer.com/wrapping-dynamic-languages-in-shell-without-an-extra-script.html</pre>
<p>Or how about &#8220;Title: link&#8221;</p>
<pre>$ curl -s 'http://bashcurescancer.com/rss/' | xml sel -t -m '//item' -v 'title' -o ': ' -v 'link' -n</pre>
<pre>Processing XML on the Command Line: http://bashcurescancer.com/processing-xml-on-the-command-line.html</pre>
<pre>Do not close stderr: http://bashcurescancer.com/do-not-close-stderr.html</pre>
<pre>prepend to a file with sponge from moreutils: http://bashcurescancer.com/prepend-to-a-file-with-sponge-from-moreutils.html</pre>
<pre>Bug in Curl is fixed: http://bashcurescancer.com/bug-in-curl-is-fixed.html</pre>
<pre>using kill to see if a process is alive: http://bashcurescancer.com/using-kill-to-see-if-a-process-is-alive.html</pre>
<pre>Performance testing - with curl: http://bashcurescancer.com/performance-testing-with-curl.html</pre>
<pre>New command: prepend: http://bashcurescancer.com/new-command-prepend.html</pre>
<pre>Shell Function - Which Webserver Does That Site Run?: http://bashcurescancer.com/shell-function-which-webserver-does-that-site-run.html</pre>
<pre>Exposing command line programs as web services: http://bashcurescancer.com/exposing-command-line-programs-as-web-services.html</pre>
<pre>Wrapping dynamic languages in shell without an extra script: http://bashcurescancer.com/wrapping-dynamic-languages-in-shell-without-an-extra-script.html</pre>
<p>You may need to do some reading on xpaths and xsl stylesheets to use the full power of the tool.</p>
]]></content:encoded>
			<wfw:commentRss>http://bashcurescancer.com/the-best-in-command-line-xml-xmlstarlet.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>prepend to a file with sponge from moreutils</title>
		<link>http://bashcurescancer.com/prepend-to-a-file-with-sponge-from-moreutils.html</link>
		<comments>http://bashcurescancer.com/prepend-to-a-file-with-sponge-from-moreutils.html#comments</comments>
		<pubDate>Thu, 17 Apr 2008 19:37:37 +0000</pubDate>
		<dc:creator>Brock Noland</dc:creator>
				<category><![CDATA[Contributions]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[moreutils]]></category>
		<category><![CDATA[patches]]></category>
		<category><![CDATA[prepend]]></category>

		<guid isPermaLink="false">http://bashcurescancer.com/?p=147</guid>
		<description><![CDATA[A few weeks I wrote about a tool, which helps you easily prepend to a file. I submitted prepend to moreutils and Joey was kind enough to point out this could be done with `sponge&#8217;.  sponge reads standard input and when done, writes it to a file: Probably the most general purpose tool in moreutils [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks I wrote about a tool, which helps you <a href="http://bashcurescancer.com/new-command-prepend.html">easily prepend to a file</a>. I submitted prepend to <a href="http://kitenet.net/~joey/code/moreutils/">moreutils</a> and Joey was kind enough to point out this could be done with `sponge&#8217;.  sponge reads standard input and when done, writes it to a file:</p>
<blockquote><p>Probably the most general purpose tool in <a href="http://kitenet.net/~joey/code/moreutils/">moreutils </a>so far is <code>sponge</code>(1), which lets you do things like this:</p>
<p><code>% sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd</code></p></blockquote>
<p>Two days ago Joey released version 0.29 of <a href="http://kitenet.net/~joey/code/moreutils/">moreutils </a>including a patch by yours truly (with much help from Joey).</p>
<blockquote><p>sponge: Handle large data sizes by using a temp file rather than by  consuming arbitrary amounts of memory. Patch by Brock Noland. <a href="http://kitenet.net/~joey/code/moreutils/news/version_0.29/">version 0.29 changelog</a></p></blockquote>
<p>Also, on a non-command line note, I found a video on Joey&#8217;s site which I thought was pretty cool, <a href="http://kitenet.net/~joey/learnstofly/">Joey Learns to Fly</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bashcurescancer.com/prepend-to-a-file-with-sponge-from-moreutils.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>using kill to see if a process is alive</title>
		<link>http://bashcurescancer.com/using-kill-to-see-if-a-process-is-alive.html</link>
		<comments>http://bashcurescancer.com/using-kill-to-see-if-a-process-is-alive.html#comments</comments>
		<pubDate>Thu, 10 Apr 2008 04:43:55 +0000</pubDate>
		<dc:creator>Brock Noland</dc:creator>
				<category><![CDATA[Brock's Tools]]></category>
		<category><![CDATA[Good Practice]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[kill]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[ps]]></category>
		<category><![CDATA[ps -ef]]></category>
		<category><![CDATA[ps faux]]></category>
		<category><![CDATA[ps grep]]></category>

		<guid isPermaLink="false">http://bashcurescancer.com/?p=141</guid>
		<description><![CDATA[I am making some changes to the moreutils sponge command. Sponge provides a method of prepending which is less specialized than my prepend util. However, it has trouble with large amounts of input. Regardless, while testing my changes, I want to watch it operate. Normally, you would just do so from a second terminal. That [...]]]></description>
			<content:encoded><![CDATA[<p>I am making some changes to the <a href="http://kitenet.net/~joey/code/moreutils/">moreutils</a> sponge command.  Sponge provides a method of prepending which is less specialized than my <a href="http://bashcurescancer.com/new-command-prepend.html">prepend</a> util. However, it has trouble with large amounts of input.</p>
<p>Regardless, while testing my changes, I want to watch it operate. Normally, you would just do so from a second terminal. That is a pain. kill -0 can be very useful for this. After backgrounding the command, I assign the pid (via the variable $!) to $pid using eval. eval is needed to stop BASH from expanding $! until after the background operation.</p>
<p>After that, I enter a while loop on kill -0 $pid, which will not kill $pid, but will return successfully until $pid has died:</p>
<pre># cat large-file-GB | ./sponge large-file-GB-copy &amp; eval 'pid=$!'; while kill -0 $pid; do sleep 10; ls -lh large-file* /tmp/sponge.*; echo;done
[1] 7937
-rw-r--r-- 1 root root 977M 2008-04-09 16:18 large-file-GB
-rw------- 1 root root 128M 2008-04-09 17:23 /tmp/sponge.JMsBWG

-rw-r--r-- 1 root root 977M 2008-04-09 16:18 large-file-GB
-rw------- 1 root root 384M 2008-04-09 17:23 /tmp/sponge.JMsBWG

-rw-r--r-- 1 root root 977M 2008-04-09 16:18 large-file-GB
-rw------- 1 root root 877M 2008-04-09 17:24 /tmp/sponge.JMsBWG

-rw-r--r-- 1 root root 977M 2008-04-09 16:18 large-file-GB
-rw-r--r-- 1 root root  20M 2008-04-09 17:24 large-file-GB-copy
-rw------- 1 root root 896M 2008-04-09 17:24 /tmp/sponge.JMsBWG

-rw-r--r-- 1 root root 977M 2008-04-09 16:18 large-file-GB
-rw-r--r-- 1 root root 413M 2008-04-09 17:25 large-file-GB-copy
-rw------- 1 root root 896M 2008-04-09 17:24 /tmp/sponge.JMsBWG

-rw-r--r-- 1 root root 977M 2008-04-09 16:18 large-file-GB
-rw-r--r-- 1 root root 836M 2008-04-09 17:25 large-file-GB-copy
-rw------- 1 root root 896M 2008-04-09 17:24 /tmp/sponge.JMsBWG

-rw-r--r-- 1 root root 977M 2008-04-09 16:18 large-file-GB
-rw-r--r-- 1 root root 920M 2008-04-09 17:25 large-file-GB-copy
[1]+  Done                    cat large-file-GB | ./sponge large-file-GB-copy
ls: cannot access /tmp/sponge.*: No such file or directory

-rw-r--r-- 1 root root 977M 2008-04-09 16:18 large-file-GB
-rw-r--r-- 1 root root 977M 2008-04-09 17:25 large-file-GB-copy
-bash: kill: (7937) - No such process
# md5sum large-file-GB*
b5c667a723a10a3485a33263c4c2b978  large-file-GB
b5c667a723a10a3485a33263c4c2b978  large-file-GB-copy</pre>
]]></content:encoded>
			<wfw:commentRss>http://bashcurescancer.com/using-kill-to-see-if-a-process-is-alive.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Exposing command line programs as web services</title>
		<link>http://bashcurescancer.com/exposing-command-line-programs-as-web-services.html</link>
		<comments>http://bashcurescancer.com/exposing-command-line-programs-as-web-services.html#comments</comments>
		<pubDate>Thu, 27 Mar 2008 23:01:30 +0000</pubDate>
		<dc:creator>Brock Noland</dc:creator>
				<category><![CDATA[guest post]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[webservice]]></category>

		<guid isPermaLink="false">http://bashcurescancer.com/exposing-command-line-programs-as-web-services.html</guid>
		<description><![CDATA[The web services paradigm of development is based on the Unix philosophy of &#8220;small is good&#8221;.  Web services should do one job, and do it well, allowing users to develop complex solutions by combining small, reliable and proven services. Why not then, expose the power of familiar Unix commands like sort, grep, gzip&#8230; to the [...]]]></description>
			<content:encoded><![CDATA[<p>The web services paradigm of development is based on the Unix philosophy of &#8220;small is good&#8221;.  Web services should do one job, and do it well, allowing users to develop complex solutions by combining small, reliable and proven services.<br />
Why not then, expose the power of familiar Unix commands like sort, grep, gzip&#8230; to the web?</p>
<p>Here is a <a href="http://bashcurescancer.com/media/scripts/to_web.py.txt">proof of concept python script</a> (<a href="http://bashcurescancer.com/media/scripts/to_web2_3.py.txt">Python 2.3 version</a>) to demonstrate.</p>
<p><span style="font-family: arial,helvetica,sans-serif;">Start services:</span></p>
<pre><span style="font-family: courier new,monospace;">$ ./to_web.py -p8008 sort &amp;
Thu Mar 27 13:45:54 2008 sort server started - 8008</span><span style="font-family: courier new,monospace;">
$ ./to_web.py -p8009 gzip &amp;
Thu Mar 27 13:46:29 2008 gzip server started - 8009</span></pre>
<p><span style="font-family: courier new,monospace;"><span style="font-family: arial,helvetica,sans-serif;">Use the services:</span><br />
</span></p>
<pre><span style="font-family: courier new,monospace;">$ for i in {1..10}; do echo ${RANDOM:0:2}; done | \
&gt; curl --data-binary @- "<a href="http://swat:8008/sort+-nr" target="_blank">http://swat:8008/sort+-nr</a>" | \
&gt; curl --data-binary @- "<a href="http://swat:8009/gzip" target="_blank">http://swat:8009/gzip</a>" | \
&gt; gunzip
97
37
23
23
21
18
11
11
10
10</span></pre>
<p>In my position, we have a database with host information &#8211; which has a command line interface. This tool has dependencies which are a painful to resolve. With <a href="http://bashcurescancer.com/media/scripts/to_web.py.txt">to_web.py</a>, we can turn the command line tool into a web service and access the data without having to satisfy those additional dependencies.</p>
<p><em>This is guest post by my esteemed colleague <strong>Adam Fokken</strong>. He can be reached here: <img src="http://spamdefeator.com/u/1ea" alt="" />Sadly, he does not have a blog. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://bashcurescancer.com/exposing-command-line-programs-as-web-services.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>3 Principles of Web Application (GUI) Design for the Command Line</title>
		<link>http://bashcurescancer.com/3-principles-of-web-application-design-for-the-command-line.html</link>
		<comments>http://bashcurescancer.com/3-principles-of-web-application-design-for-the-command-line.html#comments</comments>
		<pubDate>Mon, 10 Mar 2008 23:31:10 +0000</pubDate>
		<dc:creator>Brock Noland</dc:creator>
				<category><![CDATA[Good Practice]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://bashcurescancer.com/3-principals-of-web-application-design-for-the-command-line.html</guid>
		<description><![CDATA[When organizations need to create an application (most likely doing CRUD), they create both the application logic and user interface. Typically, this is done via a web application whose user interface is HTML. This essentially decides how the user can best utilize application logic. CRUD applications can be used seamlessly in a GUI, via the [...]]]></description>
			<content:encoded><![CDATA[<p> When organizations need to create an application (most likely doing <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a>), they create both the application logic and user interface. Typically, this is done via a web application whose user interface is HTML. This essentially decides how the user can best utilize application logic.</p>
<p>CRUD applications can be used seamlessly in a GUI, via the command line, or inside other applications by following these three principles:</p>
<ol>
<li>Decouple the user interface from the application</li>
<li>Use a standard and stateless authentication mechanism</li>
<li>REST</li>
</ol>
<p><strong>Decouple the user interface from the application<br />
</strong></p>
<p>Do not send HTML to the browser, send XML and an associated style sheet. The browser will then render the document. My <a href="http://bashcurescancer.com/sitemap.xml">sitemap</a> is an example. This makes the page both readable in a browser and machine processable. (Note, this is very basic style sheet.)</p>
<p>This way, anyone can create a client side user interface to your &#8220;application.&#8221; Your user interface, simply becomes the default user interface. Anyone can create their own. Bonus points if you provide an easy method of sharing these alternative user interfaces.</p>
<p><strong>Use a standard and stateless authentication mechanism</strong></p>
<p>Use only HTTP Basic Authentication over SSL. Being stateless and standard, this protocol is simple and leverages a ton pre-built tools. While Apache/IIS implement Basic Authentication, it is important to understand that Basic Authentication is simply a protocol for communicating credentials. You can use any authentication store. PHP.net has a good overview of <a href="http://us3.php.net/manual/en/features.http-auth.php">HTTP Authentication</a>.</p>
<p><strong> REST</strong></p>
<p>I had never heard of <a href="http://www.xfront.com/REST-Web-Services.html">REST</a> until last year. While speaking with an exceedingly intelligent colleague of mine &#8211; I explained how if I had designed this particular GUI I would have let users query data by simply modifying the URL. Example:</p>
<pre>http://gui/servers?platform=linux&amp;active=true</pre>
<p>He said, &#8220;REST!&#8221;</p>
<p>This is SO simple, just use GET, be stateless, use logical names, and allow selection via all characteristics. <em>UPDATE: This is not REST, but will get the job done. I&#8217;d prefer if you implemented REST. (See comments.)</em></p>
<p><strong> Final Thoughts</strong></p>
<p>Not all data nicely fits on a single line or few lines. However, in the <em><u><strong>vast</strong></u></em> majority of cases, records can be displayed in a grep&#8217;able format. As such, its trivial to create a parameter, say f=pt, which will output the data in some line based format. At the very least, xml can be displayed in a format with is grep&#8217;able.  Instead of:</p>
<pre>&lt;records&gt;
&lt;record id="1"&gt;
&lt;key name="abc" val="123" /&gt;
&lt;/record&gt;
&lt;record id="2"&gt;
&lt;key name="def" val="456" /&gt;
&lt;/record&gt;
&lt;/records&gt;</pre>
<p>Do this:</p>
<pre>&lt;records&gt;
&lt;record id="1"&gt;&lt;key name="abc" val="123" /&gt;&lt;/record&gt;
&lt;record id="2"&gt;&lt;key name="def" val="456" /&gt;&lt;/record&gt;
&lt;/records&gt;</pre>
<p>Many times, a separate &#8220;Web Services API&#8221; is created to allow people to extract data in a machine processable format. However, if you follow the these three principles, your GUI and API are one in the same. There is no need to create a separate non-human API. Furthermore, in my experience, there is rarely a need for reference documentation. The API is self explanatory.</p>
]]></content:encoded>
			<wfw:commentRss>http://bashcurescancer.com/3-principles-of-web-application-design-for-the-command-line.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>rpm2tgz &#8211; web interface and web service</title>
		<link>http://bashcurescancer.com/rpm2tgz-web-interface-and-web-service.html</link>
		<comments>http://bashcurescancer.com/rpm2tgz-web-interface-and-web-service.html#comments</comments>
		<pubDate>Sat, 23 Feb 2008 23:05:46 +0000</pubDate>
		<dc:creator>Brock Noland</dc:creator>
				<category><![CDATA[script]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://bashcurescancer.com/rpm2tgz-web-interface-and-web-service.html</guid>
		<description><![CDATA[My favorite site to convert rpm&#8217;s to tar gzip files appears to have shut down. As such, I wrote my own tool. It has a web interface: Convert a RPM to a tgz and (keeping inline with my thoughts on software) can be used from the command line. Five usage examples: $ wget -q "http://bashcurescancer.com/rpm2tgz.ws?url=http://bashcurescancer.com/media/rpm2tgz/telnet-0.17-39.el5.i386.rpm" [...]]]></description>
			<content:encoded><![CDATA[<p> My favorite site to convert rpm&#8217;s to tar gzip files appears to have shut down. As such, I wrote my own tool. It has a web interface: <a href="http://bashcurescancer.com/rpm2tgz.ws">Convert a RPM to a tgz</a> and (keeping inline with my thoughts on software) can be used from the command line.</p>
<p>Five usage examples:</p>
<pre>$ wget -q "http://bashcurescancer.com/rpm2tgz.ws?url=http://bashcurescancer.com/media/rpm2tgz/telnet-0.17-39.el5.i386.rpm"
$ ls -l telnet-0.17-39.el5.i386.tgz
-rw-r--r-- 1 noland noland 49804 Feb 23 17:09 telnet-0.17-39.el5.i386.tgz</pre>
<pre>$ curl -s -F "rpm=@telnet-0.17-39.el5.i386.rpm" \
"http://bashcurescancer.com/rpm2tgz.ws" &gt;telnet-0.17-39.el5.i386.tgz.1</pre>
<pre>$ curl -s -F "url=http://bashcurescancer.com/media/rpm2tgz/telnet-0.17-39.el5.i386.rpm" \
 http://bashcurescancer.com/rpm2tgz.ws &gt; telnet-0.17-39.el5.i386.tgz.2</pre>
<pre>$ curl -s "http://bashcurescancer.com/rpm2tgz.ws?url=ttp://bashcurescancer.com/media/rpm2tgz/telnet-0.17-39.el5.i386.rpm" \
&gt; telnet-0.17-39.el5.i386.tgz.3</pre>
<pre>$ wget -q -O telnet-0.17-39.el5.i386.tgz.4 \
"http://bashcurescancer.com/rpm2tgz.ws?url=http://bashcurescancer.com/media/rpm2tgz/telnet-0.17-39.el5.i386.rpm"</pre>
<p>Needless to say, if you abuse this, I will block your ip address from accessing the service. If there is an error the script will either return 404 File Not Found or 500 Internal Server Error and an empty body.  As such, you should be able to the -s expression of test, [, and [[ to check the validity of the file.</p>
]]></content:encoded>
			<wfw:commentRss>http://bashcurescancer.com/rpm2tgz-web-interface-and-web-service.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.251 seconds -->

