<?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>SurlyJake &#187; shell scripting</title>
	<atom:link href="http://www.surlyjake.com/category/linux/shell-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.surlyjake.com</link>
	<description></description>
	<lastBuildDate>Fri, 30 Dec 2011 15:28:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Script to run handbrake recursively through a folder tree</title>
		<link>http://www.surlyjake.com/2010/08/script-to-run-handbrake-recursively-through-a-folder-tree/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=script-to-run-handbrake-recursively-through-a-folder-tree</link>
		<comments>http://www.surlyjake.com/2010/08/script-to-run-handbrake-recursively-through-a-folder-tree/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 15:22:29 +0000</pubDate>
		<dc:creator>jacob</dc:creator>
				<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[bash script]]></category>
		<category><![CDATA[Handbrake]]></category>
		<category><![CDATA[recursive]]></category>

		<guid isPermaLink="false">http://www.surlyjake.com/?p=633</guid>
		<description><![CDATA[Handbrake is a fantastic tool for (among other uses), converting videos into mobile formats. It is extremely easy to use and can usually get a video properly converted in just a few clicks. To get Videos encoded for use on my phone, I use the &#8220;iPhone &#38; iPod Touch&#8221; preset. It will convert your video [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.surlyjake.com/tag/handbrake/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Handbrake">Handbrake</a> is a fantastic tool for (among other uses), converting videos into mobile formats. It is extremely easy to use and can usually get a video properly converted in just a few clicks. To get Videos encoded for use on my phone, I use the &#8220;iPhone &amp; iPod Touch&#8221; preset. It will convert your video to .mp4 as well as scale it down to a consumable size. This format will work on any smartphone I&#8217;ve seen.</p>
<p>My issue is that when converting a folder full of videos, I don&#8217;t want to have to use the gui to add a bunch of videos to the queue one by one. Its a very clicky process. This simple <a href="http://www.surlyjake.com/tag/bash-script/" class="st_tag internal_tag" rel="tag" title="Posts tagged with bash script">bash script</a> will walk handbrake through all the files in a selected folder (and its subfolders). This uses the find command to traverse recursively through a directory structure. It will place the transcoded file in the same folder as its source and change its extension to &#8220;.mp4&#8243;.</p>
<p><strong> Usage: handbrakefolder.sh [FOLDER]<br />
Run handbrake on all the files contained in [FOLDER]. (the current directory by default) </strong></p>
<pre><code>#!/bin/bash
#
# Change this to specify a different handbrake preset. You can list them by running: "HandBrakeCLI --preset-list"
#
PRESET="iPhone &amp; iPod Touch"
if [ -z "$1" ] ; then
	TRANSCODEDIR="."
else
TRANSCODEDIR="$1"
fi
find "$TRANSCODEDIR"/* -type f -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%\.*}".mp4 --preset="$PRESET"' __ {} \;</code></pre>
<p>Save that into a .sh file like &#8220;handbrakefolder.sh&#8221; and grant it the execute permission (chmod +x handbrakefolder.sh).</p>
<p>Thanks to Vinnie and <a href="http://mywiki.wooledge.org/UsingFind">http://mywiki.wooledge.org/UsingFind</a> for their help in this.</p>
<p>Now you can simply execute this <a href="http://www.surlyjake.com/tag/script/" class="st_tag internal_tag" rel="tag" title="Posts tagged with script">script</a> against a folder containing your <a href="http://www.surlyjake.com/tag/video-files/" class="st_tag internal_tag" rel="tag" title="Posts tagged with video files">video files</a>. like this:</p>
<pre><code>
For a folder structure like this:
Videos
-&gt; show1
    vid1.avi
-&gt; show2
    -&gt; season 1
        ep1.avi
        ep2.avi
    -&gt; season 2
        ep1.avi
        ep2.avi
-&gt; show3
    vid1.avi
    vid2.avi

hostname% handbrakefolder.sh Videos
...
....
...
When done, it will look like this:
Videos
-&gt; show1
    vid1.avi
    vid1.mp4
-&gt; show2
    -&gt; season 1
        ep1.avi
        ep1.mp4
        ep2.avi
        ep2.mp4
    -&gt; season 2
        ep1.avi
        ep1.mp4
        ep2.avi
        ep2.mp4
-&gt; show3
    vid1.avi
    vid1.mp4
    vid2.avi
    vid2.mp4</code></pre>
<div class="none"><div class="g-plusone" data-href="http://www.surlyjake.com/2010/08/script-to-run-handbrake-recursively-through-a-folder-tree/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.surlyjake.com/2010/08/script-to-run-handbrake-recursively-through-a-folder-tree/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Write zero&#8217;s to disk Infinite loop</title>
		<link>http://www.surlyjake.com/2010/07/write-zeros-to-disk-infinite-loop/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=write-zeros-to-disk-infinite-loop</link>
		<comments>http://www.surlyjake.com/2010/07/write-zeros-to-disk-infinite-loop/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 22:05:49 +0000</pubDate>
		<dc:creator>jacob</dc:creator>
				<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[bash script]]></category>
		<category><![CDATA[dd]]></category>

		<guid isPermaLink="false">http://www.surlyjake.com/?p=625</guid>
		<description><![CDATA[I was bored&#8230; So this is a little bash script i wrote that will write zero&#8217;s to a hard disk infinately until you press CTRL+C. It uses dcfldd instead of plain dd because i like the progress output it provides. #!/bin/bash echo -e "Which disk would you like to wipe out? (sda, sdb, sdc)? \c" [...]]]></description>
			<content:encoded><![CDATA[<p>I was bored&#8230; So this is a little <a href="http://www.surlyjake.com/tag/bash-script/" class="st_tag internal_tag" rel="tag" title="Posts tagged with bash script">bash script</a> i wrote that will write zero&#8217;s to a hard disk infinately until you press CTRL+C. It uses dcfldd instead of plain <a href="http://www.surlyjake.com/tag/dd/" class="st_tag internal_tag" rel="tag" title="Posts tagged with dd">dd</a> because i like the progress output it provides.</p>
<pre><code>#!/bin/bash
echo -e "Which disk would you like to wipe out? (sda, sdb, sdc)?   \c"
read DISK
read -p "You picked "$DISK", are you sure? (y/n)" -n 1
if [[ $REPLY =~ ^[Yy]$ ]]
then
C=1
for (( ; ; ))
do
        echo -e "\nStarting zero Sweep number "$C" ..."
        dcfldd if=/dev/zero of=/dev/$DISK
        echo "Zero's written to Disk "$C" time(s)"
        echo "[ hit CTRL+C to stop ]"
        let C=C+1
done
fi
</code></pre>
<div class="none"><div class="g-plusone" data-href="http://www.surlyjake.com/2010/07/write-zeros-to-disk-infinite-loop/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.surlyjake.com/2010/07/write-zeros-to-disk-infinite-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script to run handbrake on an entire folder</title>
		<link>http://www.surlyjake.com/2010/06/script-to-run-handbrake-on-an-entire-folder/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=script-to-run-handbrake-on-an-entire-folder</link>
		<comments>http://www.surlyjake.com/2010/06/script-to-run-handbrake-on-an-entire-folder/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 21:33:09 +0000</pubDate>
		<dc:creator>jacob</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[bash script]]></category>
		<category><![CDATA[Handbrake]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[video files]]></category>

		<guid isPermaLink="false">http://www.surlyjake.com/?p=601</guid>
		<description><![CDATA[UPDATED 8-10-10: This script has been superceeded by its newer version at http://www.surlyjake.com/2010/08/script-to-run-handbrake-recursively-through-a-folder-tree/. The new version features all of the previous features, but can also traverse recursively through a folder structure. #!/bin/bash if [ -z "$1" ] ; then TRANSCODEDIR="." else TRANSCODEDIR="$1" fi for file in "$TRANSCODEDIR"/* do HandBrakeCLI -i "${file}" -o "${file}.mp4" --preset="iPhone &#38; [...]]]></description>
			<content:encoded><![CDATA[<p><strong> UPDATED 8-10-10:<br />
This <a href="http://www.surlyjake.com/tag/script/" class="st_tag internal_tag" rel="tag" title="Posts tagged with script">script</a> has been superceeded by its newer version at <a href="http://www.surlyjake.com/2010/08/script-to-run-handbrake-recursively-through-a-folder-tree/">http://www.surlyjake.com/2010/08/script-to-run-handbrake-recursively-through-a-folder-tree/</a>. The new version features all of the previous features, but can also traverse recursively through a folder structure.</strong></p>
<pre><code>#!/bin/bash
if [ -z "$1" ] ; then
	TRANSCODEDIR="."
else
TRANSCODEDIR="$1"
fi
for file in "$TRANSCODEDIR"/*
do
	HandBrakeCLI -i "${file}" -o "${file}.mp4" --preset="iPhone &amp; iPod Touch"""
done</code></pre>
<p>Save that into a .sh file like &#8220;handbrakefolder.sh&#8221;</p>
<div class="none"><div class="g-plusone" data-href="http://www.surlyjake.com/2010/06/script-to-run-handbrake-on-an-entire-folder/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.surlyjake.com/2010/06/script-to-run-handbrake-on-an-entire-folder/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>script to update wordpress</title>
		<link>http://www.surlyjake.com/2008/11/script-to-update-wordpress/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=script-to-update-wordpress</link>
		<comments>http://www.surlyjake.com/2008/11/script-to-update-wordpress/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 21:02:37 +0000</pubDate>
		<dc:creator>jacob</dc:creator>
				<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.surlyjake.com/?p=119</guid>
		<description><![CDATA[Why? Because i&#8217;m lazy. I&#8217;ll update this to see if it works #!/bin/sh #your current site will be backed up to your home folder with the date in the name #change this to whatever you want BACKUPNAME="wordpress_site_b4_update" BACKUPDATE=`date +%y%m%d` #this is the path to your wordpress site's root SITEROOT="/usr/local/www/" #here she goez... cd ~ tar [...]]]></description>
			<content:encoded><![CDATA[<p>Why? Because i&#8217;m lazy. I&#8217;ll <a href="http://www.surlyjake.com/tag/update/" class="st_tag internal_tag" rel="tag" title="Posts tagged with update">update</a> this to see if it works<br />
<code>#!/bin/sh<br />
#your current site will be backed up to your home folder with the date in the name<br />
#change this to whatever you want<br />
BACKUPNAME="<a href="http://www.surlyjake.com/tag/wordpress/" class="st_tag internal_tag" rel="tag" title="Posts tagged with wordpress">wordpress</a>_site_b4_update"<br />
BACKUPDATE=`date +%y%m%d`<br />
#this is the path to your wordpress site's root<br />
SITEROOT="/usr/local/www/"<br />
#here she goez...<br />
cd ~<br />
tar -pczf "$BACKUPNAME""$BACKUPDATE".tar.gz "$SITEROOT"<br />
cd /usr/local<br />
fetch http://wordpress.org/latest.tar.gz<br />
tar -xzf latest.tar.gz<br />
rm latest.tar.gz<br />
cp -R wordpress/* "$SITEROOT"/<br />
rm -R wordpress<br />
chown -R www "$SITEROOT"<br />
</code></p>
<div class="none"><div class="g-plusone" data-href="http://www.surlyjake.com/2008/11/script-to-update-wordpress/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.surlyjake.com/2008/11/script-to-update-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

