<?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>MacLovin &#187; shell</title>
	<atom:link href="http://www.maclovin.de/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maclovin.de</link>
	<description>An Apple a day keeps the Windows away</description>
	<lastBuildDate>Thu, 25 Feb 2010 20:57:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Access OS X keychain from Terminal</title>
		<link>http://www.maclovin.de/2010/02/access-os-x-keychain-from-terminal/</link>
		<comments>http://www.maclovin.de/2010/02/access-os-x-keychain-from-terminal/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 20:57:44 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.maclovin.de/?p=526</guid>
		<description><![CDATA[At everyday scripting, you often need to access sensible information like passwords. A common practice is to just write them plain text into your script, but at least on a Mac, we can do better.
OS X ships with a tool called keychain. It is a central database where tools can store sensitive information like logins. [...]]]></description>
			<content:encoded><![CDATA[<p>At everyday scripting, you often need to access sensible information like passwords. A common practice is to just write them plain text into your script, but at least on a Mac, we can do better.</p>
<p>OS X ships with a tool called keychain. It is a central database where tools can store sensitive information like logins. Luckily, it is accessible from shell scripts with the command line utility <strong>security</strong>.</p>
<p>Let&#8217;s say you want to securely access an FTP server&#8217;s username and password. First of all, add a new Internet password to your keychain. To do so, just fire it up, select <em>New password</em> and enter the credentials. Remember to add the prefix http:// or ftp:// to your service name to create an Internet password.</p>
<div id="_mcePaste"><a href="http://www.maclovin.de/wp-content/uploads/2010/02/keychain-internet-password.png" title="Keychain Internet Password" rel="lightbox[526]"><img class="aligncenter size-full wp-image-532" title="Keychain Internet Password" src="http://www.maclovin.de/wp-content/uploads/2010/02/keychain-internet-password.png" alt="" width="425" height="394" /></a></div>
<p>Now you read the username like this from the command line</p>
<div id="_mcePaste">
<pre class="brush: bash;light: true">security find-internet-password -s ftp.home.com | grep "acct" | cut -d '"' -f 4</pre>
</div>
<p>The service is what you entered in keychain, but without the prefix. And finally your password</p>
<div id="_mcePaste">
<pre class="brush: bash;light: true">security 2&gt;&amp;1 &gt;/dev/null find-internet-password -gs ftp.home.com | cut -d '"' -f 2</pre>
</div>
<div id="_mcePaste">That&#8217;s all. No more plain text passwords in your script.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.maclovin.de/2010/02/access-os-x-keychain-from-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Batch renaming files in shell</title>
		<link>http://www.maclovin.de/2009/06/batch-renaming-files-in-shell/</link>
		<comments>http://www.maclovin.de/2009/06/batch-renaming-files-in-shell/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 11:05:38 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.maclovin.de/?p=300</guid>
		<description><![CDATA[Did you ever have to rename a lot of files using a similar pattern? And did you end up sitting in front of Finder or whatever your favorite file manager is and stripped of a certain prefix from the file-name or changed the extension? Well, I did. But as long as you have a terminal [...]]]></description>
			<content:encoded><![CDATA[<p>Did you ever have to rename a lot of files using a similar pattern? And did you end up sitting in front of Finder or whatever your favorite file manager is and stripped of a certain prefix from the file-name or changed the extension? Well, I did. But as long as you have a terminal at hand, you can do better. Here is how.<span id="more-300"></span></p>
<h5>Adjusting a prefix</h5>
<p>Let&#8217;s say you want to rename your ripped Futurama episodes. The current naming convention is<em> &#8220;Futurama 02&#215;12 Raging Bender.mp4&#8243;.</em> So it&#8217;s Futurama followed by a space and the season-episode identifier (season 2, episode 12), then the episode&#8217;s name and finally the extension.</p>
<p>First of all, we strip off &#8220;Futurama&#8221; and the space, because all the files are stored in a directory named &#8220;Futurama&#8221;, so we don&#8217;t need that info in the file-name anymore.</p>
<pre class="brush: bash">for i in Futurama*; do mv "$i" "${i##Futurama }"; done</pre>
<p>What we do here is to loop over all files in the current directory that start with &#8220;Futurama&#8221; and assign the file-name to the variable <em>$i</em>. We use <em>$i</em> as parameter to the <em>mv</em> command for actually renaming the file. The interesting part is its second parameter, <em>${i##Futurama }</em></p>
<p>Here we apply a modifier to the variable $i, which adjusts the returned value, but not the variable&#8217;s value itself. In this case, the modifier is <strong>##</strong> which removes a certain prefix from the variable, &#8220;Futurama &#8221; (including the space), leaving &#8220;02&#215;12 Raging Bender.mp4&#8243;.</p>
<p>Make sure to surround both parameters by quotation marks, because the file names may contain spaces.</p>
<h5>Modifying the suffix</h5>
<p>Now that we have removed the leading &#8220;Futurama &#8220;, we want to adjust the <em>mp4</em>-extension. iTunes prefers m4v, so let&#8217;s change this.</p>
<pre class="brush: bash">for i in *.mp4; do mv "$i" "${i%mp4}m4v"; done</pre>
<p>It&#8217;s very similar to what we did in the first part, except that we loop over all mp4-files and use a different variable modifier.</p>
<p>The <strong>%</strong> modifier removes the given text from the end of the variable&#8217;s value, so <em>${i%mp4}</em> removes the mp4-extension, returning <em>&#8220;02&#215;12 Raging Bender.&#8221;</em>. To add the new m4v-extension, we just include it after the braces.</p>
<p>That&#8217;s all, the files are renamed the way we wanted to. There are two tips when using this way to rename files. First of all, put the file-name in quotation marks, otherwise you will run into problems if files contain spaces, leading to undesired behaviour or errors in the best case, to loss of data in the worst case. And the second recommendation is to <em>echo</em> out the result first before actually using <em>mv</em>, just to make sure the modifier produces the expected result.</p>
<p>Do you have other tips for batch renaming files? Please explain them in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maclovin.de/2009/06/batch-renaming-files-in-shell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
