<?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>intuitive engineering &#187; bash shell</title>
	<atom:link href="http://dougmunsinger.com/tag/bash-shell/feed" rel="self" type="application/rss+xml" />
	<link>http://dougmunsinger.com</link>
	<description>doug munsinger</description>
	<lastBuildDate>Mon, 07 Jun 2010 16:44:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Fall through code to a success&#8230;</title>
		<link>http://dougmunsinger.com/2009/12/fall-through-code-to-a-success.html</link>
		<comments>http://dougmunsinger.com/2009/12/fall-through-code-to-a-success.html#comments</comments>
		<pubDate>Thu, 10 Dec 2009 15:58:10 +0000</pubDate>
		<dc:creator>doug</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[bash shell]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[nagios]]></category>

		<guid isPermaLink="false">http://dougmunsinger.com/2009/12/fall-through-code-to-a-success.html</guid>
		<description><![CDATA[I found a piece of code in a nagios alerting script that returns &#8220;success&#8221; matter what is happening with the jboss application it is checking. This script had been perpetuated as a service alerting script for years in the environs I work in, edited and passed on as working. It reads: if [failure code here]; [...]]]></description>
			<content:encoded><![CDATA[<p>I found a piece of code in a nagios alerting script that returns &#8220;success&#8221; matter what is happening with the jboss application it is checking.  </p>
<p>This script had been perpetuated as a service alerting script for years in the environs I work in, edited and passed on as working.  It reads:</p>
<p>if [failure code here]; then<br />
    # return failure to nagios nrpe daemon<br />
else<br />
   # return success to nrpe<br />
fi</p>
<p>The test for a failure failed to match, even when the test was looking for a jboss instance not present on the server.  Because the code falls through to success, everything looks just fine, all of the time.  </p>
<p>The test for failure being incorrect struck me first when I looked through the script.  The more basic flaw in logic hit me after.  I think it would be true in an alerting script you would NEVER drop through a loop to a final success.   The test would be for success, the fall-through to failure.  This would have prevented a false sense of security, and the failure to detect success would have been dealt with immediately.</p>
<p>Something like: </p>
<p>if [success code here]; then<br />
    # return success to nagios nrpe daemon<br />
else<br />
   # return failure nrpe<br />
fi</p>
<p>Obvious.  But an epiphany anyway.</p>
<p>&#8211;doug</p>
]]></content:encoded>
			<wfw:commentRss>http://dougmunsinger.com/2009/12/fall-through-code-to-a-success.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>stupid shell (and UNIX) tricks</title>
		<link>http://dougmunsinger.com/2008/07/stupid-shell-and-unix-tricks.html</link>
		<comments>http://dougmunsinger.com/2008/07/stupid-shell-and-unix-tricks.html#comments</comments>
		<pubDate>Tue, 29 Jul 2008 23:52:49 +0000</pubDate>
		<dc:creator>doug</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash shell]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">https://dougmunsinger.com/?p=97</guid>
		<description><![CDATA[I love using abobe photoshop C2&#8242;s automation &#8211; especially when resizing a series of images for the web. I would love to run linux entirely &#8211; but linux keeps falling short in graphics programs (yes, I use gimp &#8211; sorry, but Photoshop is better) and printer drivers &#8211; linux still can&#8217;t run my Canon Pixma [...]]]></description>
			<content:encoded><![CDATA[<p>I love using abobe photoshop C2&#8242;s automation &#8211; especially when resizing a series of images for the web.  I would love to run linux entirely &#8211; but linux keeps falling short in graphics programs (yes, I use gimp &#8211; sorry, but Photoshop is better) and printer drivers &#8211; linux still can&#8217;t run my Canon Pixma pro 9000 color printer.  That and every corporation I do work for has some required program or access method that seems to insist on only running on windows. </p>
<p> That said, while all operating systems suck to some degree, Windows consistently manages to suck more than most.  Cygwin supplements Windows pathetic command line with a bash shell and a lot of UNIX functionality.  </p>
<p>When you run adobe batch scripting to resize a series of jpg&#8217;s and then save them in a different directory as gif files, it insists on writing &#8220;copy&#8221; in the file name.  photograph1.jpg becomes &#8220;photograph1 copy.gif&#8221;.  To remove the &#8221; copy&#8221; string, run:</p>
<p><code>$ for i in *<br />
> do<br />
> mv "$i" "${i/\ copy.gif}".gif<br />
> done </code></p>
<p>sed and awk</p>
<p>One of the instructors I had in UNIX system administration courses was&#8230; How to put this&#8230; One brick short of a wall.  He was supposed to include sed and awk UNIX commands i the course, and he glossed over them as &#8220;something you would never use, trust me&#8221;.  A couple of years later, when I needed and had to learn the commands, I thoroughly realized he was very wrong. </p>
<p>I had to rename a series of website pages in a site redesign &#8211; including altering the names inside the pages themselves.  Here&#8217;s how I did it.</p>
<p> Here&#8217;s the command that changed one set of links from the old page to the new:</p>
<p><code><br />
for i in ` grep photographs_5.html * | awk -F : '{ print $1 }'`<br />
do<br />
echo $i<br />
sed  's/photographs_5.html/photographs_001.html/g' &lt; $i &gt; $i.1<br />
mv ${i}.1 ${i}<br />
done<br />
</code></p>
<p>This loops through and finds any files with the string &#8220;photographs_5.html&#8221; <br/><br />
echos out each file, changes (using the sed command, standard UNIX tool&#8230;) from photographs_5.html to photographs_001.html, creating a new file named [file].1,<br/><br />
then replacing the original file by moving (mv) the [file].1 file over on top of the [file].</p>
<p>I love UNIX.  Both of these were done on Windows using the bash shell in <a href="http://www.cygwin.com/" title="cygwin">cygwin</a>.  This supplies basic UNIX functionality to Windows, including the bash shell, sed and awk, ssh and rsync (by selecting the package), wget and gpg (extra package selection), and many other functions.  The setup program downloads a list, within which you can select additional packages, download and install.</p>
<p>Cygwin at least makes Windows somewhat command line friendly.</p>
<p>&mdash;dsm</p>
]]></content:encoded>
			<wfw:commentRss>http://dougmunsinger.com/2008/07/stupid-shell-and-unix-tricks.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.427 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-07-29 18:37:22 -->
