<?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>Michael Hartog &#187; shell</title>
	<atom:link href="http://www.michaelhartog.com/blog/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.michaelhartog.com/blog</link>
	<description>Detailing random internet junk since 2008</description>
	<lastBuildDate>Sun, 30 May 2010 20:25:43 +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>Shell script to extract isos from a folder</title>
		<link>http://www.michaelhartog.com/blog/2008/05/shell-script-to-extract-isos-from-a-folder/</link>
		<comments>http://www.michaelhartog.com/blog/2008/05/shell-script-to-extract-isos-from-a-folder/#comments</comments>
		<pubDate>Wed, 28 May 2008 02:34:48 +0000</pubDate>
		<dc:creator>Michael Hartog</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[iso]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.apocryblog.com/?p=59</guid>
		<description><![CDATA[I had to do this repeatedly manually at work so it took me like 2 minutes to make my first script to do it for me. It was horribly messy and looked something this: for x in $(ls -1 .); do mount -t iso9660 -o loop $x temp/; cp -r temp/* .; umount temp/; done; [...]]]></description>
			<content:encoded><![CDATA[<p>I had to do this repeatedly manually at work so it took me like 2 minutes to make my first script to do it for me. It was horribly messy and looked something this:</p>
<blockquote><p>for x in $(ls -1 .); do<br />
mount -t iso9660 -o loop $x temp/;<br />
cp -r temp/* .;<br />
umount temp/;<br />
done;</p></blockquote>
<p>Which did the job but was horribly messing on doing it more than once with tons of errors and stuff.</p>
<p>When I came home I decided to make it much better. I even included how long it takes to do the whole process, which was harder than the process itself.<br />
<span id="more-59"></span></p>
<p>So right now it looks like:</p>
<blockquote><p>before=$(date +%s);<br />
mkdir temp/;#tempdir<br />
for x in $(ls -1 ./*.iso); do<br />
echo Currently unpacking $x | sed -e &#8216;s/.\///; s/.iso//&#8217;; #remove extra output<br />
mount -t iso9660 -o loop $x temp/; #mounts iso<br />
cp -ru temp/* .;<br />
umount temp/;<br />
done;<br />
rmdir temp/; #cleanup<br />
after=$(date +%s);<br />
elapsed=$(expr $after &#8211; $before); #time calculations<br />
((hour=$elapsed/60/60));<br />
((min=$elapsed/60-hour*60));<br />
((sec=$elapsed-hour*60*60-$min*60));<br />
echo &#8220;Elapsed time: &#8220;`printf &#8220;%02d&#8221; $hour`&#8221;:&#8221;`printf &#8220;%02d&#8221; $min`&#8221;:&#8221;`printf &#8220;%02d&#8221; $sec`;</p></blockquote>
<p>Which does everything I want it too, even the pain in the ass zero-padding of the times. Remember to chmod +x &lt;filename&gt; if you want to use it <img src='http://www.michaelhartog.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>Edit: Well, I messed up a few things, I only tested in under one minute times and the shell on that server only contains sh and ash. Here is the revised edition:</p>
<blockquote><p>#! /bin/sh<br />
before=$(date +%s);<br />
mkdir temp/;#tempdir<br />
for x in $(ls -1 ./*.iso); do<br />
echo Currently unpacking $x | sed -e &#8216;s/.\///; s/.iso//&#8217;; #remove extra output<br />
mount -t iso9660 -o loop $x temp/; #mounts iso<br />
cp -ru temp/* .;<br />
umount temp/;<br />
done;<br />
rmdir temp/; #cleanup<br />
after=$(date +%s);<br />
elapsed=$(expr $after &#8211; $before); #time calculations<br />
hour=&#8221;$(expr &#8220;$elapsed&#8221; &#8216;/&#8217; &#8217;60&#8242; &#8216;/&#8217; &#8217;60&#8242;)&#8221;<br />
min=&#8221;$(expr &#8220;$elapsed&#8221; &#8216;/&#8217; &#8217;60&#8242; &#8216;-&#8217; &#8216;$hour&#8217; &#8216;*&#8217; &#8217;60&#8242;)&#8221;<br />
sec=&#8221;$(expr &#8220;$elapsed&#8221; &#8216;-&#8217; &#8216;$hour&#8217; &#8216;*&#8217; &#8217;60&#8242; &#8216;*&#8217; &#8217;60&#8242; &#8216;-&#8217; &#8216;$min&#8217; &#8216;*&#8217; &#8217;60&#8242;)&#8221;<br />
echo &#8220;Elapsed time: &#8220;`printf &#8220;%02d&#8221; $hour`&#8221;:&#8221;`printf &#8220;%02d&#8221; $min`&#8221;:&#8221;`printf &#8220;%02d&#8221; $sec`;</p></blockquote>
<p>And now I know that sh is *really* annoying to do math in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michaelhartog.com/blog/2008/05/shell-script-to-extract-isos-from-a-folder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
