<?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>~chuck/blog &#187; bash</title>
	<atom:link href="http://www.ozymo.com/explosions/tag/bash/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ozymo.com</link>
	<description>What more could you want?</description>
	<lastBuildDate>Tue, 17 Oct 2023 03:57:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Lazy Umounting</title>
		<link>http://www.ozymo.com/explosions/348</link>
		<comments>http://www.ozymo.com/explosions/348#comments</comments>
		<pubDate>Fri, 11 Jun 2010 13:46:53 +0000</pubDate>
		<dc:creator>chuck</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://www.ozymo.com/?p=348</guid>
		<description><![CDATA[I came across a mounted sdb1 partition, but the physical device didn&#8217;t exist. This was on a Red Hat EL 5 box. No files in the mount point, obviously, no users logged in but me, and I wasn&#8217;t standing in the directory. Even lsof couldn&#8217;t show me anything about that directory, and I almost cried]]></description>
			<content:encoded><![CDATA[<p>I came across a mounted sdb1 partition, but the physical device didn&#8217;t exist. This was on a Red Hat EL 5 box.</p>
<p>No files in the mount point, obviously, no users logged in but me, and I wasn&#8217;t standing in the directory. Even lsof couldn&#8217;t show me anything about that directory, and I almost cried when fuser -km reported nothing killed.</p>
<p>Umount gave this error:</p>
<pre># umount /dev/sdb1
umount: /dev/sdb1: device is busy
umount: /dev/sdb1: device is busy</pre>
<p>In the man page, I found the -l option for umount. The Lazy unmount. It says this:</p>
<blockquote><p>Detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore.</p></blockquote>
<p>Sounds good to me, and it worked, too. Just watch out for data loss.</p>
<p>/cs</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozymo.com/explosions/348/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Arguments to your Scripts</title>
		<link>http://www.ozymo.com/explosions/8</link>
		<comments>http://www.ozymo.com/explosions/8#comments</comments>
		<pubDate>Tue, 05 Feb 2008 07:10:37 +0000</pubDate>
		<dc:creator>chuck</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.ozymo.com/~chuck/blog/?p=8</guid>
		<description><![CDATA[I like bash. It is simple and straight forward. In the words of Master Foo, &#8220;Is it he who writes the ten thousand lines, or he who, perceiving the emptiness of the task, gains merit by not coding?&#8221; One of the easiest things to do in a bash script that has more than one function]]></description>
			<content:encoded><![CDATA[<p>I like bash.</p>
<p>It is simple and straight forward. In the words of <a href="http://www.catb.org/~esr/writings/unix-koans/" title="The Cathedral and the Bazaar">Master Foo</a>, &#8220;<span class="quote">Is it he who writes the ten thousand lines, or he who, perceiving the emptiness of the task, gains merit by not coding?&#8221;</span></p>
<p>One of the easiest things to do in a bash script that has more than one function is to add the capability of the script to allow arguments to specify it&#8217;s action.</p>
<p><span id="more-8"></span> You&#8217;ll notice, if you look at an init script (for instance, /etc/init.d/httpd on a Red Hat server), that roughly this same method is used to allow for arguments like &#8220;start&#8221; and &#8220;stop&#8221; et al.</p>
<p>I was working on an <a href="http://www.linuxfromscratch.org/" title="Best Linux Tutorial Ever">LFS</a> installation, and scripted a little foo to get the sources and patches without having to manually download each one.  Basically, it used this command to parse the pages with the listings of source tarballs or patches, and find the URL:</p>
<blockquote><p>lynx -source file:///home/chuck/src/lfs-clfs/book/ppc/materials/packages.html | grep -A1 Download: | grep -v Download: | awk -F&#8217;&#8221;&#8216; &#8216;{print $2}&#8217; | grep -v &#8216;^$</p></blockquote>
<p>As you can see, I downloaded the book source so that I wouldn&#8217;t spam their site (a little Internet courtesy).  I was presented with a list of links to source files.  Hooray!</p>
<p>I expanded into cross-compiling linux for a PPC laptop I had laying around, and ended up needing to expand my script to be able to tell it which sources and patches to download.  After a little <a href="http://www.oreilly.com/catalog/bash3/index.html" title="Bash - every noob's nightmare">research</a>, I came across the &#8220;case&#8221; control statement.  In the case statement, I was able to specify which sources and/or patches I wanted by adding an argument to the script.  Here is the case statement:</p>
<blockquote><p> case $1 in<br />
gens)<br />
ARGS=$GENERAL_SOURCES<br />
;;<br />
genp)<br />
ARGS=$GENERAL_PATCHES<br />
;;<br />
ppcs)<br />
ARGS=$PPC_SOURCES<br />
;;<br />
ppcp)<br />
ARGS=$PPC_PATCHES<br />
;;<br />
all)<br />
ARGS=`echo $GENERAL_SOURCES $GENERAL_PATCHES $PPC_SOURCES $PPC_PATCHES`<br />
;;<br />
*)<br />
ARGS=&#8221;"<br />
;;<br />
esac</p></blockquote>
<p>As an added bonus, you can see that on the last argument (denoted by &#8220;*)&#8221;), I was able to catch all other arguments besides the ones I specified.  If the argument didn&#8217;t match what was supposed to be there, it would set the $ARGS variable to NULL, or &#8220;&#8221;.</p>
<p>With a little &#8220;if/else&#8221; statement, I then was able to specify that if the $ARGS variable had no value, to echo the usage of the script, or else run the command and download my sources.</p>
<p>Bear in mind, though that the $ARGS variable should be subject to some pretty good input checking before putting a script like this into production, because someone could easily hack it:</p>
<blockquote><p>$ ARGS=&#8221;(rm -rf /)&#8221;; ./script.sh</p></blockquote>
<p>WARNING: do NOT run the above command, as your box will be broke!  I will not fix it for you!  You&#8217;ve been warned!</p>
<p>/cs</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozymo.com/explosions/8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
