<?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>lab.joelGillman.com &#187; bash</title>
	<atom:link href="http://lab.joelgillman.com/archives/tag/bash/feed" rel="self" type="application/rss+xml" />
	<link>http://lab.joelgillman.com</link>
	<description>Sketches, Code Bites and Toys</description>
	<lastBuildDate>Thu, 05 Nov 2009 23:19:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pseudo Work (fwork)</title>
		<link>http://lab.joelgillman.com/archives/159_pseudo-work</link>
		<comments>http://lab.joelgillman.com/archives/159_pseudo-work#comments</comments>
		<pubDate>Thu, 05 Nov 2009 22:16:30 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[clock]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[source control]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=159</guid>
		<description><![CDATA[This script takes a text file (any text file should) and displays it one line at a time with short delays in between.  In other words, you can run this script to make it look like your computer is actually doing something worthwhile.
I had searched around the internet a few times but never really [...]]]></description>
			<content:encoded><![CDATA[<p>This script takes a text file (any text file should) and displays it one line at a time with short delays in between.  In other words, you can run this script to make it <em>look</em> like your computer is actually doing something worthwhile.</p>
<p>I had searched around the internet a few times but never really found anything like this, but that doesn&#8217;t mean it doesn&#8217;t look.  Maybe I&#8217;m just a bad internet searcher.  <a href="http://lab.joelgillman.com/archives/159_pseudo-work">Script after the jump</a>. <span id="more-159"></span></p>
<p><br/></p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:435px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co0">#!/bin/bash</span><br />
<br />
<span class="co0">#####################################################</span><br />
<span class="co0"># Pseudo Work (fwork) Script - by Joel Gillman 2009</span><br />
<span class="co0"># lab.joelgillman.com/archives/159_pseudo-work</span><br />
<span class="co0"># </span><br />
<span class="co0"># Please feel free to edit and change this as you</span><br />
<span class="co0"># &nbsp;like! If &nbsp;you do make any edits I would be curious</span><br />
<span class="co0"># &nbsp;to see what you've done so drop me a line!</span><br />
<span class="co0"># </span><br />
<span class="co0"># DISCLAIMER</span><br />
<span class="co0"># I am in no way a bash scripting expert. Most of what</span><br />
<span class="co0"># &nbsp;I write is copy and paste and trial and error.</span><br />
<span class="co0"># &nbsp;While this script shouldn't hurt anything in your</span><br />
<span class="co0"># &nbsp;system don't hold me responsible if it does! Use</span><br />
<span class="co0"># &nbsp;at your own risk.</span><br />
<span class="co0">#####################################################</span><br />
<br />
<br />
<span class="co0">## test if file (default or otherwise)</span><br />
<span class="kw1">if</span> <span class="br0">&#91;</span> <span class="st0">&quot;$1&quot;</span> = <span class="st_h">''</span> <span class="br0">&#93;</span>; <span class="kw1">then</span><br />
&nbsp; &nbsp; <span class="re2">filename</span>=<span class="st0">&quot;<span class="es2">$HOME</span>/garbage.txt&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#91;</span> <span class="re5">-e</span> <span class="re1">$filename</span> <span class="br0">&#93;</span>; <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">sleep</span> <span class="nu0">0</span><br />
&nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">echo</span> <span class="st0">&quot;No file specified and default file '~/garbage.txt' not found.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">exit</span><br />
&nbsp; &nbsp; <span class="kw1">fi</span><br />
<span class="kw1">elif</span> <span class="br0">&#91;</span> <span class="re5">-e</span> $<span class="nu0">1</span> <span class="br0">&#93;</span>; <span class="kw1">then</span><br />
&nbsp; &nbsp; <span class="re2">filename</span>=$<span class="nu0">1</span><br />
<span class="kw1">else</span><br />
&nbsp; &nbsp; <span class="kw3">echo</span> <span class="st0">&quot;No file found at $1&quot;</span><br />
&nbsp; &nbsp; <span class="kw3">exit</span><br />
<span class="kw1">fi</span><br />
<br />
<span class="co0">## execute fakeness</span><br />
<span class="kw1">while</span> <span class="kw2">read</span> p; <span class="kw1">do</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#91;</span> <span class="st0">&quot;<span class="es4">$(($RANDOM % 10)</span>)&quot;</span> <span class="re5">-eq</span> <span class="nu0">1</span> <span class="br0">&#93;</span>; <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">let</span> <span class="st0">&quot;R1 = (<span class="es2">$RANDOM</span> % 2)&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">elif</span> <span class="br0">&#91;</span> <span class="st0">&quot;<span class="es4">$(($RANDOM % 50)</span>)&quot;</span> <span class="re5">-eq</span> <span class="nu0">1</span> <span class="br0">&#93;</span>; <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">let</span> <span class="st0">&quot;R1 = (<span class="es2">$RANDOM</span> % 20)&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">let</span> <span class="st0">&quot;R1 = 0&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">fi</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw3">let</span> <span class="st0">&quot;R2 = (<span class="es2">$RANDOM</span> % 10)&quot;</span><br />
&nbsp; &nbsp; <span class="kw3">echo</span> <span class="re1">$p</span><br />
&nbsp; &nbsp; <span class="kw2">sleep</span> <span class="re1">$R1</span>.<span class="re1">$R2</span><br />
<span class="kw1">done</span> <span class="sy0">&lt;</span> <span class="re1">$filename</span></div></div>
<p><a href="http://lab.joelgillman.com/thepress/wp-content/uploads/2009/11/fwork.zip">Download a zip&#8217;d version of the script</a>.<br />
You can <a href="http://lab.joelgillman.com/thepress/wp-content/uploads/2009/11/garbage.txt">download the (2.5MB) text file</a> I&#8217;ve been using.</p>
<p>Let me know what you think!  Any improvements or suggestions would be greatly appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/159_pseudo-work/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iSightCapture, now with more SSH!</title>
		<link>http://lab.joelgillman.com/archives/130_isightcapture-now-with-more-ssh</link>
		<comments>http://lab.joelgillman.com/archives/130_isightcapture-now-with-more-ssh#comments</comments>
		<pubDate>Thu, 30 Apr 2009 18:28:50 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[isight]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[screencapture]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ssh-keys]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=130</guid>
		<description><![CDATA[I think this kind of thing is pretty awesome.  Take a picture from your iSight.  Take a screencapture.  Upload them both to a remote server. WHY DOESN&#8217;T EVERYONE WANT TO DO THIS?!  Maybe you do, now you can (hopefully).
Firstly, props to Dylan O&#8217;Donnell, who wrote the original script.  I was [...]]]></description>
			<content:encoded><![CDATA[<p>I think this kind of thing is pretty awesome.  Take a picture from your iSight.  Take a screencapture.  Upload them both to a remote server. WHY DOESN&#8217;T EVERYONE WANT TO DO THIS?!  Maybe you do, now you can (hopefully).<span id="more-130"></span></p>
<p>Firstly, props to Dylan O&#8217;Donnell, who wrote the original script.  I was personally unsatisfied with FTP because it&#8217;s insecure and I always run into technical troubles with it. Probably because I never took the time to learn what I was doing with FTP via command line&#8230; But I favor SCP for my file transferring needs.<br/><br/></p>
<p>I also added a screen cap functionality because there&#8217;s all kinds of cool things you can do with that down the line.  Time-lapse animation, security, you name it!<br/><br/></p>
<p>If you want the iSight captures to work you must download and install <a href='http://lab.joelgillman.com/thepress/wp-content/uploads/2009/04/isightcapture.zip'>isightcapture</a>! I&#8217;ve installed it to /usr/sbin/ and hardcoded the script to look there. If you don&#8217;t know what you&#8217;re doing, I suggest you do the same.<br/><br/></p>
<p><strong>&#8220;Installing&#8221; isightcapture (assuming it&#8217;s unzipped and on your desktop):</strong></p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:435px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">user$ <span class="kw2">sudo</span> <span class="kw2">cp</span> ~<span class="sy0">/</span>Desktop<span class="sy0">/</span>isightcapture <span class="sy0">/</span>usr<span class="sy0">/</span>sbin<span class="sy0">/</span></div></div>
<p>Quick rundown of what&#8217;s happening here:<br />
- Grab the date and time info and prepare the filenames (YearMonthDayHourMinuteSecond)<br />
- Take a picture with the iSight, save it to a folder (~/Documents/pics/)<br />
- Take a screencap, save it to the same folder (~/Documents/pics/)<br />
- Resize all of the jpgs in the pics folder so they&#8217;re no more than 800px in any dimention<br />
- Check to see if the computer has a network connection, if it does upload the files to a remote server (via scp) and delete the local images. If there&#8217;s no connection, do nothing (images will try to upload next time the script is run)</p>
<p>In order for this to work <strong><em>you must have SSH Keys setup with the server you are connecting to</em></strong>. If you don&#8217;t it will not work.  If you google &#8220;ssh keys&#8221; there are a million ways to do it but this is the site that actually got it working on my modern mac: <a href="http://www.webficient.com/2007/11/16/mac-and-ssh-keys">http://www.webficient.com/2007/11/16/mac-and-ssh-keys</a><br/><br/></p>
<p>Here&#8217;s a quick and dirty run down of how to do that, but I&#8217;m just copying from <a href="http://www.webficient.com/2007/11/16/mac-and-ssh-keys">Phil&#8217;s post</a> so don&#8217;t blame me if it doesn&#8217;t work for you :)<br/><br/></p>
<p>Generate the ssh key (obviously replace the CAPS stuff with your info). When asked for a passphrase just hit enter, this will make an empty passphrase which, I admit, is very insecure but it&#8217;s better than nothing and the script won&#8217;t work with a passphrase :( :</p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:435px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">user$ <span class="kw2">ssh-keygen</span> <span class="re5">-t</span> rsa <span class="re5">-f</span> ~<span class="sy0">/</span>.ssh<span class="sy0">/</span>id_rsa</div></div>
<p>If you&#8217;ve never used SSH to make an outgoing connect on the machine you are connecting to you will also need to create the ssh folder on that machine and make it so only your user can read it:</p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:435px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">user$ <span class="kw2">ssh</span> USER<span class="sy0">@</span>YOUR.SERVER.COM <span class="st_h">'mkdir ~/.ssh;chmod 700 ~/.ssh'</span></div></div>
<p>Now copy your public key (id_rsa.pub) to the server you&#8217;re connecting to (I always name the copy on the server &#8220;temp_pub_key&#8221; so I know exactly what file I need):</p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:435px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">user$ <span class="kw2">scp</span> ~<span class="sy0">/</span>.ssh<span class="sy0">/</span>id_rsa.pub USER<span class="sy0">@</span>YOUR.SERVER.COM:~<span class="sy0">/</span>.ssh<span class="sy0">/</span>temp_pub_key</div></div>
<p>Now connect to the remote server and navigate to ~/.ssh/</p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:435px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">remote-user$ <span class="kw3">cd</span> ~<span class="sy0">/</span>.ssh<span class="sy0">/</span></div></div>
<p>On the server, check to see if the file &#8220;authorized_keys&#8221; exists, if it doesn&#8217;t rename your &#8220;temp_pub_key&#8221; to &#8220;authorized_keys:</p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:435px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">remote-user$ <span class="kw2">mv</span> temp_pub_key authorized_keys</div></div>
<p>If &#8220;authorized_keys&#8221; already exists then you want to add your public key to the end of the file:</p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:435px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">remote-user$ <span class="kw2">cat</span> temp_pub_key <span class="sy0">&amp;</span>gt;<span class="sy0">&amp;</span>gt; authorized_keys</div></div>
<p>If &#8220;authorized_keys&#8221; didn&#8217;t already exists, you&#8217;ll also have to set the permissions of the authorized_keys file:</p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:435px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">ssh</span> USER<span class="sy0">@</span>YOUR.SERVER.COM <span class="st_h">'chmod 644 ~/.ssh/authorized_keys2'</span></div></div>
<p>Here is the automation script originally written by Dylan O&#8217;Donnell with my tweaks and editing for SSH and screencaps.</p>
<div class="codecolorer-container bash " style="overflow:auto;white-space:nowrap;width:435px;height:300px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co0">#!/bin/bash</span><br />
<span class="co0">#</span><br />
<span class="co0"># Original iSight Auto Upload Script - by Dylan O'Donnell 2006</span><br />
<span class="co0"># Edited for ssh and made more awesome by Joel Gillman 2009 </span><br />
<span class="co0">#####################################################</span><br />
<span class="co0"># Edit CAPITALS with appropriate details </span><br />
<span class="co0"># &nbsp;Notes : You must have ssh-keys setup with the server you are </span><br />
<span class="co0"># &nbsp; &nbsp; &nbsp; &nbsp;: uploading to before hand. Otherwise this will not work.</span><br />
<span class="co0"># &nbsp; &nbsp; &nbsp; &nbsp;:</span><br />
<span class="co0"># &nbsp; &nbsp; &nbsp; &nbsp;: Try here for tutorial on ssh-keys (worked for me)</span><br />
<span class="co0"># &nbsp; &nbsp; &nbsp; &nbsp;: &nbsp;http://www.webficient.com/2007/11/16/mac-and-ssh-keys</span><br />
<span class="co0">#</span><br />
<span class="co0">#####################################################</span><br />
<br />
<span class="co0"># Generate filename based on date stamp</span><br />
<span class="re2">picture</span>=$<span class="br0">&#40;</span><span class="kw2">date</span> +<span class="sy0">%</span>y<span class="sy0">%</span>m<span class="sy0">%</span>d<span class="sy0">%</span>H<span class="sy0">%</span>M<span class="sy0">%</span>S<span class="br0">&#41;</span>_pic.jpg;<br />
<span class="re2"><span class="kw2">screen</span></span>=$<span class="br0">&#40;</span><span class="kw2">date</span> +<span class="sy0">%</span>y<span class="sy0">%</span>m<span class="sy0">%</span>d<span class="sy0">%</span>H<span class="sy0">%</span>M<span class="sy0">%</span>S<span class="br0">&#41;</span>_scr.jpg;<br />
<br />
<span class="co0"># Take iSight Photo and store with datestamp filename</span><br />
<span class="sy0">/</span>usr<span class="sy0">/</span>sbin<span class="sy0">/</span>isightcapture <span class="re5">-w</span> <span class="nu0">640</span> <span class="re5">-h</span> <span class="nu0">480</span> <span class="re5">-t</span> jpg <span class="sy0">/</span>Users<span class="sy0">/</span>USERNAME<span class="sy0">/</span>Documents<span class="sy0">/</span>pics<span class="sy0">/</span><span class="re1">$picture</span>;<br />
<br />
<span class="co0"># Take screen capture</span><br />
<span class="sy0">/</span>usr<span class="sy0">/</span>sbin<span class="sy0">/</span>screencapture <span class="re5">-C</span> <span class="re5">-m</span> <span class="re5">-t</span> jpg <span class="re5">-x</span> <span class="sy0">/</span>Users<span class="sy0">/</span>USERNAME<span class="sy0">/</span>Documents<span class="sy0">/</span>pics<span class="sy0">/</span><span class="re1">$screen</span>;<br />
<br />
<span class="co0">#resize the pictures so they're not too big</span><br />
<span class="sy0">/</span>usr<span class="sy0">/</span>bin<span class="sy0">/</span>sips <span class="re5">--resampleHeightWidthMax</span> <span class="nu0">800</span> <span class="sy0">/</span>Users<span class="sy0">/</span>USERNAME<span class="sy0">/</span>Documents<span class="sy0">/</span>pics<span class="sy0">/*</span>.jpg<br />
<br />
<span class="co0"># Generate semaphore for connectivity by pinging NASA</span><br />
<span class="re2">isconnected</span>=$<span class="br0">&#40;</span><span class="kw2">ping</span> <span class="re5">-c</span> <span class="nu0">1</span> www.nasa.gov <span class="sy0">|</span> <span class="kw2">grep</span> <span class="nu0">64</span> <span class="sy0">|</span> <span class="kw2">wc</span> <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'{print $1}'</span><span class="br0">&#41;</span>;<br />
<br />
<span class="co0"># Wait a few seconds to see if it's connected.</span><br />
<span class="kw2">sleep</span> <span class="nu0">3</span>;<br />
<br />
<span class="co0"># If connected...</span><br />
<span class="kw1">if</span> <span class="br0">&#91;</span> <span class="st0">&quot;<span class="es2">$isconnected</span>&quot;</span> <span class="re5">-eq</span> <span class="st0">&quot;1&quot;</span> <span class="br0">&#93;</span>; <span class="kw1">then</span> <br />
<br />
&nbsp; &nbsp; <span class="sy0">/</span>usr<span class="sy0">/</span>bin<span class="sy0">/</span><span class="kw2">scp</span> <span class="sy0">/</span>Users<span class="sy0">/</span>USERNAME<span class="sy0">/</span>Documents<span class="sy0">/</span>pics<span class="sy0">/*</span> USERNAME<span class="sy0">@</span>YOUR.SERVER.COM:<span class="st0">&quot;REMOTE/PATH&quot;</span>;<br />
<br />
&nbsp; &nbsp; <span class="co0"># Wait a few seconds, just to make sure everything is clear and complete</span><br />
&nbsp; &nbsp; <span class="kw2">sleep</span> <span class="nu0">4</span>;<br />
<br />
&nbsp; &nbsp; <span class="co0"># delete local images</span><br />
&nbsp; &nbsp; <span class="kw2">rm</span> <span class="re5">-f</span> <span class="sy0">/</span>Users<span class="sy0">/</span>USERNAME<span class="sy0">/</span>Documents<span class="sy0">/</span>pics<span class="sy0">/*</span>.jpg;<br />
<br />
<span class="kw1">else</span> <br />
&nbsp; &nbsp; <span class="co0"># If not connected.. leave captures there until next time. </span><br />
&nbsp; &nbsp; <span class="kw3">echo</span> <span class="st0">&quot;No Connection, Image not transferred or deleted.&quot;</span>;<br />
<span class="kw1">fi</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/130_isightcapture-now-with-more-ssh/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
