<?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; automation</title>
	<atom:link href="http://lab.joelgillman.com/archives/tag/automation/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>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>
