<?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>things &#38; stuff &#187; Scripting</title>
	<atom:link href="http://www.curlybrace.com/words/category/technology/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.curlybrace.com/words</link>
	<description>Pictures.  Now with more words!</description>
	<lastBuildDate>Mon, 05 Jul 2010 21:47: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>Converting MP3 to AAC</title>
		<link>http://www.curlybrace.com/words/2010/02/05/converting-mp3-to-aac/</link>
		<comments>http://www.curlybrace.com/words/2010/02/05/converting-mp3-to-aac/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 07:27:21 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=895</guid>
		<description><![CDATA[Here is a script I wrote to convert MP3 files to AAC for my Softbank 821SC phone. The script uses FFmpeg, which I downloaded from here. @echo off REM --------------------------------------------------------------------------- REM Set the following variable to the ffmpeg.exe path on your system. REM --------------------------------------------------------------------------- set FFMPEG_PATH="c:\tools\FFmpeg\ffmpeg.exe" REM make sure the user provided an argument. if [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a script I wrote to convert MP3 files to AAC for my Softbank 821SC phone.  The script uses FFmpeg, which I downloaded from <a href="http://ffmpeg.arrozcru.org/autobuilds/">here</a>.</p>
<blockquote>
<pre>
@echo off

REM ---------------------------------------------------------------------------
REM  Set the following variable to the ffmpeg.exe path on your system.
REM ---------------------------------------------------------------------------
set FFMPEG_PATH="c:\tools\FFmpeg\ffmpeg.exe"

REM make sure the user provided an argument.
if NOT "%~1" == "" goto ARGS_OK

REM bad arguments, print error and exit.
echo.
echo    Usage examples:
echo       mp3toaac.bat file_to_convert.mp3
echo       mp3toaac.bat *.mp3
echo       mp3toaac.bat some_directory\*.mp3
exit /b 1

:ARGS_OK

REM use for/in so that we can accept individual files or wildcards.
for %%i in ("%~1") do %FFMPEG_PATH% -i "%%~i" "%%~ni.aac"

echo.
echo Done.

exit /b 0
</pre>
</blockquote>
<p>Interesting elements of this batch file:</p>
<ul>
<li />Use of <tt>for</tt>/<tt>in</tt> in order to accept both filenames and wildcards.
<li />Use of <tt>%~<i>X</i></tt> to strip parentheses from a filename variable.
<li />Use of <tt>%~n<i>X</i></tt> to strip the extension from a filename variable (i.e. retrieve the basename).
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2010/02/05/converting-mp3-to-aac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH Tunneling Windows RDC</title>
		<link>http://www.curlybrace.com/words/2009/07/05/ssh-port-forwarding-windows-rdc/</link>
		<comments>http://www.curlybrace.com/words/2009/07/05/ssh-port-forwarding-windows-rdc/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 22:26:17 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=740</guid>
		<description><![CDATA[This article explains how to securely port-forward Windows Remote Desktop (Terminal Services) over SSH, using standard SSH command line syntax. If you prefer to use GUI SSH tools, such as PuTTY, there are other guides for that. Terminology Notes My terminology assumes that you are connecting to a machine on your home network, which is [...]]]></description>
			<content:encoded><![CDATA[<p>This article explains how to securely port-forward Windows Remote Desktop (Terminal Services) over SSH, using standard SSH command line syntax.  If you prefer to use GUI SSH tools, such as PuTTY, <a href="http://theillustratednetwork.mvps.org/Ssh/RemoteDesktopSSH.html">there are other guides for that</a>.</p>
<h4>Terminology Notes</h4>
<p>My terminology assumes that you are connecting to a machine on your home network, which is protected by a firewall.  However, the diagrams and commands are valid regardless of whether the remote network is at home or not.</p>
<p>Additionally, I use <tt><i>RDCHOST</i></tt> to represent the local name or IP of your RDC server <b>within the home network</b>, and <tt><i>my_home_ip</i></tt> to represent your home IP address as visible from the Internet.</p>
<h3>Prerequisites</h3>
<ul>
<li />Depending on network configuration, port-forwarding may have to be configured on the firewall.
<li />An SSH client (e.g. <a href="http://www.cygwin.com/">Cygwin&#8217;s OpenSSH</a> for Windows) must be installed on the local machine.
<li />An SSH server (e.g. <a href="http://www.cygwin.com/">Cygwin&#8217;s OpenSSHD</a> for Windows) must be present on some machine within the home network.
<li />SSH keys must be generated and deployed appropriately.
</ul>
<h3>SSH Command Syntax</h3>
<blockquote><p><tt>ssh -C -N -L <i>localPort</i>:<i>destinationHost</i>:3389 <i>proxyHost</i></tt></p>
<p />
<ul>
<li /><i>localPort</i> is the port on localhost through which you wish to connect.
<li /><i>destinationHost</i> is the Remote Desktop host, <b>as it appears on the home network</b>.
<li /><i>proxyHost</i> is the host running SSHD, through which you will tunnel.
</ul>
</blockquote>
<h3>Configuration 1:  Discrete Servers</h3>
<p>This configuration has the firewall port-forward SSH to a server on the home network, which proxies the connection to the RDC server:</p>
<blockquote><pre>                       +-----------[ Home Network ]---------------+
                       |                                          |
localhost <----> Home Firewall <---> SSH Server <---> RDC Server  |
                       |                                          |
                       +------------------------------------------+</pre>
</blockquote>
<p>Command line:</p>
<blockquote><p><tt>ssh -C -N -L 6009:<i>RDCHOST</i>:3389 <i>my_home_ip</i></tt></p></blockquote>
<h3>Configuration 2:  Combined RDC &#038; SSH Servers</h3>
<p>In this configuration, the RDC server also has an SSH server, and the firewall port-forwards directly to it:</p>
<blockquote><pre>                       +------[ Home Network ]-----+
                       |                           |
localhost <----> Home Firewall <-----> RDC &#038; SSH   |
                       |                Server     |
                       +---------------------------+</pre>
</blockquote>
<p>Command line:</p>
<blockquote><p><tt>ssh -C -N -L 6009:localhost:3389 <i>my_home_ip</i></tt></p></blockquote>
<h3>Configuration 3:  Firewall as SSH Server</h3>
<p>In this configuration, the firewall acts as the SSH server, proxying the connection directly to the RDC server on the home network:</p>
<blockquote><pre>                       +----[ Home Network ]----+
                       |                        |
localhost <----> Home Firewall <---> RDC Server |
                  &#038; SSH Server                  |
                       |                        |
                       +------------------------+
</pre>
</blockquote>
<p>Command line:</p>
<blockquote><p><tt>ssh -C -N -L 6009:<i>RDCHOST</i>:3389 <i>my_home_ip</i></tt></p></blockquote>
<h3>Additional Suggestions</h3>
<p>Rather than specifying the IP address of your home firewall, I suggest using <a href="http://www.dyndns.com/">DynDNS</a> to get a dynamic DNS entry.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2009/07/05/ssh-port-forwarding-windows-rdc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Organizing Files by Date Using Find</title>
		<link>http://www.curlybrace.com/words/2008/07/13/organizing-files-by-date-using-find/</link>
		<comments>http://www.curlybrace.com/words/2008/07/13/organizing-files-by-date-using-find/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 19:10:42 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=147</guid>
		<description><![CDATA[I had taken pictures using a friend&#8217;s SD card. He copied all the files to my flash drive, but this left me without a nice, tidy directory structure. Normally, I organize my photos like: 2008 2008_06_27 2008_06_28 2008_06_29 First off, I needed to list the files by date: ls -lt This showed me that I [...]]]></description>
			<content:encoded><![CDATA[<p>I had taken pictures using a friend&#8217;s SD card.  He copied all the files to my flash drive, but this left me without a nice, tidy directory structure.  Normally, I organize my photos like:</p>
<blockquote><pre>2008
   2008_06_27
   2008_06_28
   2008_06_29</pre>
</blockquote>
<p>First off, I needed to list the files by date:</p>
<blockquote><pre>ls -lt</pre>
</blockquote>
<p>This showed me that I had files from the 27th, 28th, and 29th in a single directory.  So I created a directory for each date.</p>
<p>Next, I used <tt>find</tt> with the <tt>-newer</tt> and <tt>-exec</tt> switches to execute a move command on each file newer than a particular file.</p>
<p>By looking at the <tt>ls -lt</tt> output, I found the last photo taken on each day.  IMG_6369.JPG was the last taken on the 28th, and IMG_6284.JPG was the last taken on the 27th.</p>
<p>To move all of the files taken on the 28th and 29th, I used this command:</p>
<blockquote><pre>find . -type f -newer IMG_6284.JPG -exec mv {} 2008_06_28 \;</pre>
</blockquote>
<p>Now, all files taken after the 27th are located in the 2008_06_28 directory.  Now, I change into that directory, and execute:</p>
<blockquote><pre>find . -type f -newer IMG_6369.JPG -exec mv {} ../2008_06_29 \;</pre>
</blockquote>
<p>Now I&#8217;m left with all the photos from the 27th in the main directory.  Those could easily be moved with:</p>
<blockquote><pre>find . -maxdepth 1 -type f -exec mv {} ../2008_06_27 \;</pre>
</blockquote>
<p>I&#8217;m sure there is a quicker, cleaner way to do this, but for the limited number of subdirectories I had to filter into, this was reasonably efficient.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2008/07/13/organizing-files-by-date-using-find/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extracting a Version Number From a Text File Using Batch Files and Cygwin</title>
		<link>http://www.curlybrace.com/words/2008/07/11/extracting-a-version-number/</link>
		<comments>http://www.curlybrace.com/words/2008/07/11/extracting-a-version-number/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 01:50:47 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=146</guid>
		<description><![CDATA[We have a version.h file. It contains lines such as: #define VERSION_MAJOR 3 #define VERSION_MINOR 1 By piping this through grep, I can get the line I&#8217;m looking for: c:\>grep "VERSION_MAJOR" version.h #define VERSION_MAJOR 3 But what I really want is the version number within the line, so I pipe this through sed: c:\>grep "VERSION_MAJOR" [...]]]></description>
			<content:encoded><![CDATA[<p>We have a version.h file.  It contains lines such as:</p>
<blockquote><pre>#define VERSION_MAJOR     3
#define VERSION_MINOR     1</pre>
</blockquote>
<p>By piping this through <tt>grep</tt>, I can get the line I&#8217;m looking for:</p>
<blockquote><pre>c:\>grep "VERSION_MAJOR" version.h
#define VERSION_MAJOR     3</pre>
</blockquote>
<p>But what I really want is the version number within the line, so I pipe this through <tt>sed</tt>:</p>
<blockquote><pre>c:\>grep "VERSION_MAJOR" version.h | sed -e "s/^.* VERSION_MAJOR\s*\([0-9]\+\)/\1/g"
3</pre>
</blockquote>
<p>So now we have extracted the version number corresponding to &#8220;VERSION_MAJOR&#8221;.  However, in order to conditionally branch in our batch script, we need to get this value into an environmental variable.  In bash, this would be accomplished with backticks.  As it turns out, Windows batch files <b>do</b> provide similar functionality, but through a much clumsier means:</p>
<blockquote><pre>c:\>for /f "tokens=3" %i in ('grep " VERSION_MAJOR" version.h') do set MAJORVERSION=%i
c:\>echo %MAJORVERSION%
3</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2008/07/11/extracting-a-version-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stripping Vertical Whitespace Using tr</title>
		<link>http://www.curlybrace.com/words/2008/06/16/stripping-vertical-whitespace-tr/</link>
		<comments>http://www.curlybrace.com/words/2008/06/16/stripping-vertical-whitespace-tr/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 18:05:37 +0000</pubDate>
		<dc:creator>Jeff Fitzsimons</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.curlybrace.com/words/?p=130</guid>
		<description><![CDATA[The Translate command, tr, is available on all Unix-y systems, including Cygwin. tr -d will delete the specified characters from a stream. Several handy escape sequences are provided for stripping newlines, carriage returns, and form-feeds: \f &#8211; form feed \n &#8211; new line \r &#8211; return Since tr is deleting characters, not strings, we can [...]]]></description>
			<content:encoded><![CDATA[<p>The Translate command, <tt>tr</tt>, is available on all Unix-y systems, including <a href="http://www.cygwin.com">Cygwin</a>.  <tt>tr -d</tt> will delete the specified characters from a stream.   Several handy escape sequences are provided for stripping newlines, carriage returns, and form-feeds:</p>
<ul>
<li /><tt>\f</tt> &#8211; form feed
<li /><tt>\n</tt> &#8211; new line
<li /><tt>\r</tt> &#8211; return
</ul>
<p>Since <tt>tr</tt> is deleting <i>characters</i>, not strings, we can simply specify all of these in a single command:</p>
<blockquote><p><tt>cat input.txt | tr -d \r\n\f > output.txt</tt></p></blockquote>
<p>Another way to assemble this command:</p>
<blockquote><p><tt>tr -d \r\n\f < input.txt > output.txt</tt></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.curlybrace.com/words/2008/06/16/stripping-vertical-whitespace-tr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
