<?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>Marius van Witzenburg &#187; Script</title>
	<atom:link href="http://kitara.nl/tag/script/feed/" rel="self" type="application/rss+xml" />
	<link>http://kitara.nl</link>
	<description>We fight for our survival, we fight!</description>
	<lastBuildDate>Sun, 20 May 2012 15:39:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to send a message to your iPhone via Pushme.to with PHP or Bash and Curl</title>
		<link>http://kitara.nl/2011/06/14/how-to-send-a-message-to-your-iphone-via-pushme-to-with-php-or-bash-and-curl/</link>
		<comments>http://kitara.nl/2011/06/14/how-to-send-a-message-to-your-iphone-via-pushme-to-with-php-or-bash-and-curl/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 12:05:21 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Curl]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[GEOM]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Pushme]]></category>
		<category><![CDATA[S.M.A.R.T.]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[SMS]]></category>
		<category><![CDATA[Text]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=241</guid>
		<description><![CDATA[After having Pushme.to installed on my iPhone for over 3 months now I finally had the time to work on some scrips to make it work in different languages for use on servers that I manage. The PHP version is the less version I use but may be handy for some people. PHP Version: function [...]]]></description>
			<content:encoded><![CDATA[<p>After having <a href="http://pushme.to/">Pushme.to</a> installed on my <a href="http://www.apple.com/iphone/">iPhone</a> for over 3 months now I finally had the time to work on some scrips to make it work in different languages for use on servers that I manage.</p>
<p>The <a href="http://php.net/">PHP</a> version is the less version I use but may be handy for some people.</p>
<p><strong>PHP Version</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> pushMeTo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$signature</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://pushme.to/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">'message='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;signature='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$signature</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
pushMeTo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Hello world!'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'God'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A more used version is the commandline (<a href="http://www.gnu.org/software/bash/">Bash</a>) version:</p>
<p><strong>Bash version</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">username</span>=<span style="color: #ff0000;">&quot;username&quot;</span>
<span style="color: #007800;">message</span>=<span style="color: #ff0000;">&quot;Hello world&quot;</span>
<span style="color: #007800;">signature</span>=<span style="color: #ff0000;">&quot;God&quot;</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>curl <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;message=<span style="color: #007800;">$message</span>&quot;</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;signature=<span style="color: #007800;">$signature</span>&quot;</span> <span style="color: #ff0000;">&quot;http://pushme.to/<span style="color: #007800;">$username</span>/&quot;</span></pre></div></div>

<p>I currently use these for server monitoring on <a href="http://www.freebsd.org/">FreeBSD</a> like the <a href="http://www.freebsd.org/doc/handbook/geom.html">GEOM</a> Raid bay and <a href="http://en.wikipedia.org/wiki/S.M.A.R.T.">S.M.A.R.T.</a> status of the disks and website monitoring which works quite nice. And in case the internet connection drops I have a backup via <a href="http://en.wikipedia.org/wiki/SMS">SMS</a> with a serial connected cellphone. So this should be quite failsafe <img src='http://kitara.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>If you have any other language that you want to use such as <a href="http://www.perl.org/">Perl</a> just let me know and I could write it for you.</p>
<p>I hope you find these scripts useful. Happy texting! <img src='http://kitara.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kitara.nl/2011/06/14/how-to-send-a-message-to-your-iphone-via-pushme-to-with-php-or-bash-and-curl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Download Redtube movies with a simple PHP class</title>
		<link>http://kitara.nl/2011/06/14/download-redtube-movies-with-a-simple-php-class/</link>
		<comments>http://kitara.nl/2011/06/14/download-redtube-movies-with-a-simple-php-class/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 11:52:07 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[Movies]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Porn]]></category>
		<category><![CDATA[Redtube]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=227</guid>
		<description><![CDATA[For donations I build everything... Simply put this file on a server where you want and start downloading class RedTube &#123; function form&#40;&#41; &#123; echo '&#60;form method=&#34;post&#34;&#62;&#60;input type=&#34;text&#34; name=&#34;url&#34;&#62;&#60;input type=&#34;submit&#34;&#62;&#60;/form&#62;'; &#125; &#160; function download&#40;$url = null&#41; &#123; if &#40;$this-&#62;validate&#40;$url&#41;&#41; &#123; $content = $this-&#62;fetch&#40;$url&#41;; &#160; preg_match&#40;'#&#60;h1 class=&#34;videoTitle&#34;&#62;(.*)&#60;/h1&#62;#', $content, $d1&#41;; //preg_match('#&#60;source src=\'(.*)\' type=\\\&#34;video/mp4\\\&#34;&#62;#', $content, $d2); preg_match&#40;'#&#60;source src=\'(.*)\' [...]]]></description>
			<content:encoded><![CDATA[<p>For donations I build everything...</p>
<p>Simply put this file on a server where you want and start downloading <img src='http://kitara.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> RedTube <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;form method=&quot;post&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;url&quot;&gt;&lt;input type=&quot;submit&quot;&gt;&lt;/form&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> download<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#&lt;h1 class=&quot;videoTitle&quot;&gt;(.*)&lt;/h1&gt;#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$d1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;">//preg_match('#&lt;source src=\'(.*)\' type=\\\&quot;video/mp4\\\&quot;&gt;#', $content, $d2);</span>
            <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#&lt;source src=\'(.*)\' type=\'video/mp4\'&gt;#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$d2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: application/octet-stream&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.mp4'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>       
        <span style="color: #009900;">&#125;</span>       
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> validate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#^http://(www.)?redtube.com/[0-9]+$#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>       
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> fetch<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stream</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">echo</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4096</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>       
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$buffer</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4096</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>       
            <span style="color: #009900;">&#125;</span>       
            <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>       
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$rt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RedTube<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$rt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">download</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$rt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kitara.nl/2011/06/14/download-redtube-movies-with-a-simple-php-class/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>How to fix inconsistent line ending (EOL) style with find and Perl</title>
		<link>http://kitara.nl/2010/08/25/how-to-fix-inconsistent-line-ending-eol-style-with-find-and-perl/</link>
		<comments>http://kitara.nl/2010/08/25/how-to-fix-inconsistent-line-ending-eol-style-with-find-and-perl/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 09:56:24 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[CFM]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Ending]]></category>
		<category><![CDATA[EOL]]></category>
		<category><![CDATA[Find]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Inconsistent]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Line]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PL]]></category>
		<category><![CDATA[Replace]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[TXT]]></category>

		<guid isPermaLink="false">http://mariusvw.com/?p=4967</guid>
		<description><![CDATA[If you work with subversion you might get this error when you got files that have been edited on different operating systems like Windows, Linux, FreeBSD or Mac OS X. Well, the fix is quite simple. You simply replace the wrong line endings with right ones depending of which you want. In my situation I [...]]]></description>
			<content:encoded><![CDATA[<p>If you work with subversion you might get this error when you got files that have been edited on different operating systems like Windows, Linux, FreeBSD or Mac OS X.</p>
<p>Well, the fix is quite simple. You simply replace the wrong line endings with right ones depending of which you want. In my situation I want unix style line endings.</p>
<p>Replace in PHP/JavaScript files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.php'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/rn/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.php'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/r/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.js'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/rn/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.js'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/r/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;</pre></div></div>

<p>In case you want to replace them in multiple file types you can adjust the command. In this example we want to replace in the following file types:</p>
<ol>
<li>asp</li>
<li>cfm</li>
<li>css</li>
<li>html</li>
<li>js</li>
<li>php</li>
<li>pl</li>
<li>txt</li>
</ol>
<p>Use the following commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.asp'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.cfm'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.css'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.html'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.js'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.php'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.pl'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.txt'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/rn/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.asp'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.cfm'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.css'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.html'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.js'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.php'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.pl'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.txt'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/r/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;</pre></div></div>

<p>Keep in mind, you may use these commands on your own risk. I'm not responsible if you lose your work <img src='http://kitara.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Now you should be able to commit your files again <img src='http://kitara.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kitara.nl/2010/08/25/how-to-fix-inconsistent-line-ending-eol-style-with-find-and-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to backup from a Western Digital Sharespace to another Sharespace via rsync and FreeBSD</title>
		<link>http://kitara.nl/2010/03/23/how-to-backup-from-a-western-digital-sharespace-to-another-sharespace-via-rsync-and-freebsd/</link>
		<comments>http://kitara.nl/2010/03/23/how-to-backup-from-a-western-digital-sharespace-to-another-sharespace-via-rsync-and-freebsd/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 16:23:44 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Rsync]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Sharespace]]></category>
		<category><![CDATA[Sync]]></category>
		<category><![CDATA[WDC]]></category>
		<category><![CDATA[Western DIgital]]></category>

		<guid isPermaLink="false">http://mariusvw.com/?p=1438</guid>
		<description><![CDATA[This script simply syncs from a WD ShareSpace drive to another WD ShareSpace drive. It gets started from a other server which is in my case FreeBSD. You might need this: How to enable SSH on a Western Digital ShareSpace Create the following files on FreeBSD: /backup/sharespace/ssh-wrapper #!/bin/sh sh /backup/run &#38; /backup/sharespace/run #!/bin/sh # WD [...]]]></description>
			<content:encoded><![CDATA[<p>This script simply syncs from a WD ShareSpace drive to another WD ShareSpace drive. It gets started from a other server which is in my case FreeBSD.</p>
<p>You might need this: <a href="http://kitara.nl/2011/06/30/how-to-enable-ssh-on-a-western-digital-sharespace/" title="How to enable SSH on a Western Digital ShareSpace" >How to enable SSH on a Western Digital ShareSpace</a></p>
<p>Create the following files on FreeBSD:</p>
<p><em>/backup/sharespace/ssh-wrapper</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>run <span style="color: #000000; font-weight: bold;">&amp;</span></pre></div></div>

<p><em>/backup/sharespace/run</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># WD ShareSpace sync script v1.1</span>
<span style="color: #666666; font-style: italic;"># By Marius van Witzenburg &lt;info@kitara.nl&gt;</span>
<span style="color: #666666; font-style: italic;"># http://kitara.nl</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Works with busybox 1.1.1 and newer versions.</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Settings</span>
<span style="color: #007800;">source</span>=<span style="color: #ff0000;">&quot;192.168.8.4&quot;</span>
<span style="color: #007800;">target</span>=<span style="color: #ff0000;">&quot;192.168.8.9&quot;</span>
<span style="color: #007800;">mailto</span>=<span style="color: #ff0000;">&quot;info@kitara.nl&quot;</span>
<span style="color: #007800;">mailfrom</span>=<span style="color: #ff0000;">&quot;noreply@kitara.nl&quot;</span>
<span style="color: #007800;">daemon</span>=<span style="color: #ff0000;">&quot;yes&quot;</span>
<span style="color: #007800;">force</span>=<span style="color: #ff0000;">&quot;no&quot;</span>
<span style="color: #007800;">waittime</span>=<span style="color: #000000;">5</span>
<span style="color: #007800;">maxlogs</span>=<span style="color: #000000;">48</span>
<span style="color: #007800;">beforetime</span>=<span style="color: #000000;">6</span>
<span style="color: #007800;">aftertime</span>=<span style="color: #000000;">20</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># DO NOT CHANGE BELOW!</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin
<span style="color: #007800;">PID</span>=<span style="color: #007800;">$$</span>
<span style="color: #007800;">rarg</span>=<span style="color: #ff0000;">&quot;-aWvz&quot;</span>
&nbsp;
<span style="color: #007800;">curdir</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${PID}</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>run.pid
cleanup<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>key
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #800000;">${curdir}</span>
    <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-ax</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${target}</span> <span style="color: #ff0000;">&quot;test -f /backup/rsyncd.pid &amp;&amp; kill <span style="color: #780078;">`cat /backup/rsyncd.pid`</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$?</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
s_hup<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;*** SIGHUP! Ignoring... ***&quot;</span>
    <span style="color: #666666; font-style: italic;">#exit $?</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
s_int<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;*** SIGINT! Exiting... ***&quot;</span>
    cleanup 
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;From: <span style="color: #007800;">${mailfrom}</span>nTo: <span style="color: #007800;">${mailto}</span>nSubject: ShareSpace backup.nnSIGINT! Exiting...&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>msmtp <span style="color: #800000;">${mailto}</span>
    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>run.pid
    <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #800000;">${JOB}</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span> 
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
s_term<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;*** SIGTERM! Exiting... ***&quot;</span>
    cleanup
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;From: <span style="color: #007800;">${mailfrom}</span>nTo: <span style="color: #007800;">${mailto}</span>nSubject: ShareSpace backup.nnSIGTERM! Exiting...&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>msmtp <span style="color: #800000;">${mailto}</span>
    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>run.pid
    <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #800000;">${JOB}</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">trap</span> s_hup SIGHUP
<span style="color: #7a0874; font-weight: bold;">trap</span> s_int SIGINT
<span style="color: #7a0874; font-weight: bold;">trap</span> s_term SIGTERM
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${daemon}</span>&quot;</span> = <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;Having a rest for the first run...&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">30</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
    <span style="color: #007800;">JOB</span>=<span style="color: #007800;">$!</span>
    <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #800000;">${JOB}</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #666666; font-style: italic;"># Time to backup?</span>
    <span style="color: #007800;">hour</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #ff0000;">&quot;+%H&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${hour}</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${beforetime}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$hour</span>&quot;</span> <span style="color: #660033;">-gt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${aftertime}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #666666; font-style: italic;"># Change the 1 to 1-3 depending on which load you want</span>
        <span style="color: #007800;">loadavg</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">uptime</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/.*average: ([0-9]).*/1/g'</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${loadavg}</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${force}</span>&quot;</span> = <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">alive</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-ax</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;BatchMode=yes&quot;</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;ConnectTimeout 5&quot;</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${target}</span> <span style="color: #ff0000;">&quot;echo 2&gt;&amp;1&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${alive}</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
            <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #007800;">user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom<span style="color: #7a0874; font-weight: bold;">&#41;</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #000000; font-weight: bold;">%</span>N<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> md5sum <span style="color: #000000; font-weight: bold;">|</span> uuencode <span style="color: #660033;">-m</span> -<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> 2p <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-c3-43</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-c1-</span><span style="color: #800000;">${1:-16}</span><span style="color: #000000; font-weight: bold;">`</span>
                <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
                <span style="color: #007800;">pass</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom<span style="color: #7a0874; font-weight: bold;">&#41;</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #000000; font-weight: bold;">%</span>N<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> md5sum <span style="color: #000000; font-weight: bold;">|</span> uuencode <span style="color: #660033;">-m</span> -<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> 2p <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-c3-43</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-c1-</span><span style="color: #800000;">${1:-16}</span><span style="color: #000000; font-weight: bold;">`</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${pass}</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>key
&nbsp;
                <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log
                <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>server <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>server
&nbsp;
                <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run.<span style="color: #800000;">${maxlogs}</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run.<span style="color: #800000;">${maxlogs}</span>
                <span style="color: #007800;">lcur</span>=<span style="color: #800000;">${maxlogs}</span>
                <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${lcur}</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
                <span style="color: #000000; font-weight: bold;">do</span>
                    <span style="color: #007800;">lpre</span>=<span style="color: #800000;">${lcur}</span>
                    <span style="color: #007800;">lcur</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #800000;">${lcur}</span> - <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
                    <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run.<span style="color: #800000;">${lcur}</span>.gz <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run.<span style="color: #800000;">${lcur}</span>.gz <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run.<span style="color: #800000;">${lpre}</span>.gz
                <span style="color: #000000; font-weight: bold;">done</span>
                <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run.1
                <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run.1 <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run.1
&nbsp;
                <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run
&nbsp;
                logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;Creating rsync server configuration&quot;</span>
&nbsp;
                <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>server<span style="color: #000000; font-weight: bold;">/</span>rsyncd.conf <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>EOF
pid <span style="color: #c20cb9; font-weight: bold;">file</span> = <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>rsyncd.pid
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>shares<span style="color: #7a0874; font-weight: bold;">&#93;</span>
path = <span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/</span>
comment = Rsync Server
uid = root
gid = jewab
use <span style="color: #c20cb9; font-weight: bold;">chroot</span> = no
<span style="color: #c20cb9; font-weight: bold;">read</span> only = no
list = no
auth <span style="color: #c20cb9; font-weight: bold;">users</span> = <span style="color: #800000;">${user}</span>
secrets <span style="color: #c20cb9; font-weight: bold;">file</span> = <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>rsync.users
EOF
&nbsp;
                <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>server<span style="color: #000000; font-weight: bold;">/</span>rsync.users <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>EOF
<span style="color: #800000;">${user}</span>:<span style="color: #800000;">${pass}</span>
EOF
&nbsp;
                <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>server<span style="color: #000000; font-weight: bold;">/</span>start <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>EOF
<span style="color: #666666; font-style: italic;">#!/bin/sh</span>
rsync <span style="color: #660033;">--daemon</span> <span style="color: #660033;">--config</span>=<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>rsyncd.conf <span style="color: #000000; font-weight: bold;">&amp;</span>
EOF
&nbsp;
                <span style="color: #666666; font-style: italic;"># Transfer server files</span>
                rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'ssh -ax'</span> <span style="color: #800000;">${rarg}</span> <span style="color: #660033;">--timeout</span>=<span style="color: #000000;">30</span> <span style="color: #660033;">--delete</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>server<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #800000;">${target}</span>:<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
                <span style="color: #007800;">JOB</span>=<span style="color: #007800;">$!</span>
                <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #800000;">${JOB}</span>
&nbsp;
                <span style="color: #666666; font-style: italic;"># Start rsync server</span>
                <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-ax</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${target}</span> <span style="color: #ff0000;">&quot;sh /backup/start &gt; /dev/null 2&gt;&amp;1; exit&quot;</span>
                <span style="color: #007800;">JOB</span>=<span style="color: #007800;">$!</span>
                <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #800000;">${JOB}</span>
&nbsp;
                <span style="color: #666666; font-style: italic;"># Sync internal shares and exclude usb shares</span>
                logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;Syncing internal shares...&quot;</span>
                rsync <span style="color: #800000;">${rarg}</span> <span style="color: #660033;">--timeout</span>=<span style="color: #000000;">60</span> <span style="color: #660033;">--password-file</span>=<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>key <span style="color: #660033;">--exclude</span>=<span style="color: #ff0000;">&quot;/usb[1-3]-1share1&quot;</span> <span style="color: #660033;">--delete</span> <span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/</span> rsync:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #800000;">${user}</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${target}</span><span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
                <span style="color: #007800;">JOB</span>=<span style="color: #007800;">$!</span>
                <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #800000;">${JOB}</span>
                <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-2</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run <span style="color: #000000; font-weight: bold;">|</span> logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.info <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span>
&nbsp;
                <span style="color: #666666; font-style: italic;"># Sync usb shares if connected</span>
                <span style="color: #000000; font-weight: bold;">for</span> x <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-ax</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${target}</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^d&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $9 }'</span><span style="color: #000000; font-weight: bold;">`</span>
                <span style="color: #000000; font-weight: bold;">do</span>
                    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`expr ${x} : '(usb[0-9]-[0-9]share[0-9])'`</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
                    <span style="color: #000000; font-weight: bold;">then</span>
                        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/shares/<span style="color: #007800;">${x}</span>/&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
                            <span style="color: #000000; font-weight: bold;">then</span>
                            logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;Syncing <span style="color: #007800;">${x}</span>...&quot;</span>
                            rsync <span style="color: #800000;">${rarg}</span> <span style="color: #660033;">--timeout</span>=<span style="color: #000000;">60</span> <span style="color: #660033;">--password-file</span>=<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>key <span style="color: #660033;">--delete</span> <span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${x}</span><span style="color: #000000; font-weight: bold;">/</span> rsync:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #800000;">${user}</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${target}</span><span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${x}</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
                            <span style="color: #007800;">JOB</span>=<span style="color: #007800;">$!</span>
                            <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #800000;">${JOB}</span>
                            <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-2</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>run <span style="color: #000000; font-weight: bold;">|</span> logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.info <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span>
                        <span style="color: #000000; font-weight: bold;">fi</span>
                    <span style="color: #000000; font-weight: bold;">fi</span>
                <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
                <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">5</span>
&nbsp;
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;From: <span style="color: #007800;">${mailfrom}</span>nTo: <span style="color: #007800;">${mailto}</span>nSubject: ShareSpace backup.nnCycle finished...&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>msmtp <span style="color: #800000;">${mailto}</span>
&nbsp;
                <span style="color: #666666; font-style: italic;"># Shutdown rsync server</span>
                cleanup
            <span style="color: #000000; font-weight: bold;">else</span>
                logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;No access to '<span style="color: #007800;">${target}</span>' - aborting&quot;</span>
            <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #000000; font-weight: bold;">else</span>
            logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;Load average on '<span style="color: #007800;">${source}</span>' is <span style="color: #007800;">${loadavg}</span> - aborting&quot;</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;Not the time to make backups - sleeping&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Daemonize or stop?</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${daemon}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;Backup finished&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">break</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Cycle</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;Waiting for cycle (<span style="color: #007800;">${waittime}</span> minutes)...&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #800000;">${waittime}</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">60</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
    <span style="color: #007800;">JOB</span>=<span style="color: #007800;">$!</span>
    <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #800000;">${JOB}</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #ff0000;">'backup'</span> <span style="color: #ff0000;">&quot;Running cycle...&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p><em>/backup/sync.sh</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/local/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Sync backup system on ShareSpace drive</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">ip</span>=<span style="color: #ff0000;">&quot;192.168.8.4&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Fix permissions</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>sharespace<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-type</span> d <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #ff0000;">'{}'</span> ; 
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>sharespace<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> <span style="color: #ff0000;">'{}'</span> ; 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-- Shutting down current backup&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-ax</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${ip}</span> <span style="color: #ff0000;">&quot;test -f /backup/run.pid &amp;&amp; kill <span style="color: #780078;">`cat /backup/run.pid`</span>&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">15</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-- Syncing new files&quot;</span>
rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'ssh -ax'</span> <span style="color: #660033;">-aWv</span> <span style="color: #660033;">--timeout</span>=<span style="color: #000000;">30</span> <span style="color: #660033;">--exclude</span> <span style="color: #ff0000;">'.svn'</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--delete-excluded</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>sharespace<span style="color: #000000; font-weight: bold;">/</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${ip}</span>:<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-- Restarting backup&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-ax</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${ip}</span> <span style="color: #ff0000;">&quot;sh /backup/ssh-wrapper &gt; /dev/null 2&gt;&amp;1; exit&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>After creating these files set these permissions and start the script:</p>
<blockquote><p>
chmod 700 /backup/sync.sh<br />
/backup/sync.sh
</p></blockquote>
<p>Keep in mind that you setup SSH-keys before you use these scripts <img src='http://kitara.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://kitara.nl/2010/03/23/how-to-backup-from-a-western-digital-sharespace-to-another-sharespace-via-rsync-and-freebsd/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How to backup from a Western Digital Sharespace to another Sharespace (v2)</title>
		<link>http://kitara.nl/2010/03/13/how-to-backup-from-a-western-digital-sharespace-to-another-sharespace-v2/</link>
		<comments>http://kitara.nl/2010/03/13/how-to-backup-from-a-western-digital-sharespace-to-another-sharespace-v2/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 20:22:13 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Rsync]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Sharespace]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Sync]]></category>
		<category><![CDATA[Synchronisation]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[Western DIgital]]></category>

		<guid isPermaLink="false">http://mariusvw.com/?p=1376</guid>
		<description><![CDATA[I earlier wrote a script to sync two Western Digital ShareSpace drives. Since that was written in a hurry I thought lets have another good look at it... I changed the checks for USB drives and sync the complete the shares directory instead of only the shares. The following script is a new rewritten version [...]]]></description>
			<content:encoded><![CDATA[<p>I earlier wrote a script to sync two Western Digital ShareSpace drives. Since that was written in a hurry I thought lets have another good look at it...</p>
<p>I changed the checks for USB drives and sync the complete the shares directory instead of only the shares.</p>
<p>The following script is a new rewritten version of the old script which works faster for my use.</p>
<p>You may modify it to suit your situation but please leave the credits in the file <img src='http://kitara.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>You might need this: <a href="http://kitara.nl/2011/06/30/how-to-enable-ssh-on-a-western-digital-sharespace/" title="How to enable SSH on a Western Digital ShareSpace" >How to enable SSH on a Western Digital ShareSpace</a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># WD ShareSpace sync script v1.1</span>
<span style="color: #666666; font-style: italic;"># By Marius van Witzenburg &lt;info@kitara.nl&gt;</span>
<span style="color: #666666; font-style: italic;"># http://kitara.nl</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Works with busybox 1.1.1 and newer versions.</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Settings</span>
<span style="color: #007800;">src_ip</span>=<span style="color: #ff0000;">&quot;172.20.20.22&quot;</span>
<span style="color: #007800;">mailto</span>=<span style="color: #ff0000;">&quot;marius@kitara.nl&quot;</span>
<span style="color: #007800;">mailfrom</span>=<span style="color: #ff0000;">&quot;noreply@kitara.nl&quot;</span>
<span style="color: #007800;">daemon</span>=<span style="color: #ff0000;">&quot;yes&quot;</span>
<span style="color: #007800;">force</span>=<span style="color: #ff0000;">&quot;no&quot;</span>
<span style="color: #007800;">waittime</span>=<span style="color: #000000;">5</span>
<span style="color: #007800;">maxlogs</span>=<span style="color: #000000;">48</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># DO NOT CHANGE BELOW!</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin
<span style="color: #007800;">PID</span>=<span style="color: #007800;">$$</span>
&nbsp;
<span style="color: #007800;">pwd</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">root</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #007800;">$0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">logdir</span>=<span style="color: #800000;">${root}</span><span style="color: #000000; font-weight: bold;">/</span>logs
<span style="color: #007800;">logfile</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #800000;">${root}</span>
&nbsp;
cleanup<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #666666; font-style: italic;">#rm -f ${log}</span>
    <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$?</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
s_hup<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;*** SIGHUP! Exiting... ***&quot;</span>
    cleanup
    <span style="color: #666666; font-style: italic;">#exit $?</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
s_int<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;*** SIGINT! Exiting... ***&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;From: <span style="color: #007800;">${mailfrom}</span>nTo: <span style="color: #007800;">${mailto}</span>nSubject: ShareSpace backup.nnSIGINT! Exiting...&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>msmtp <span style="color: #800000;">${mailto}</span>
    <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #800000;">${JOB}</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
s_term<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;*** SIGTERM! Exiting... ***&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;From: <span style="color: #007800;">${mailfrom}</span>nTo: <span style="color: #007800;">${mailto}</span>nSubject: ShareSpace backup.nnSIGTERM! Exiting...&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>msmtp <span style="color: #800000;">${mailto}</span>
    <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #800000;">${JOB}</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">trap</span> s_hup SIGHUP
<span style="color: #7a0874; font-weight: bold;">trap</span> s_int SIGINT
<span style="color: #7a0874; font-weight: bold;">trap</span> s_term SIGTERM
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${daemon}</span>&quot;</span> = <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;Having a rest for the first run...&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">30</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
    <span style="color: #007800;">JOB</span>=<span style="color: #007800;">$!</span>
    <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #800000;">${JOB}</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Loop and loop and loop...</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #666666; font-style: italic;"># Check if ssh host is up and running.</span>
    <span style="color: #007800;">alive</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-ax</span> <span style="color: #660033;">-c</span> blowfish <span style="color: #660033;">-q</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;BatchMode=yes&quot;</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;ConnectTimeout 5&quot;</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${src_ip}</span> <span style="color: #ff0000;">&quot;echo 2&gt;&amp;1&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${alive}</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #666666; font-style: italic;"># Change the 1 to 1-3 depending on which load you want</span>
        <span style="color: #666666; font-style: italic;">#loadavg=`ssh -ax -c blowfish root@${src_ip} uptime | sed -e &quot;s/.*load average: (.*...), (.*...), (.*...)/1/&quot; -e &quot;s/ //g&quot;`</span>
        <span style="color: #007800;">loadavg</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-ax</span> <span style="color: #660033;">-c</span> blowfish root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${src_ip}</span> <span style="color: #c20cb9; font-weight: bold;">uptime</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/.*average: ([0-9]).*/1/g'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${loadavg}</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${force}</span>&quot;</span> = <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #666666; font-style: italic;"># Be sure we have a log dir</span>
            <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-d</span> <span style="color: #800000;">${logdir}</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #800000;">${logdir}</span>
&nbsp;
            <span style="color: #666666; font-style: italic;"># Shift logs</span>
            <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span>.<span style="color: #800000;">${maxlogs}</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span>.<span style="color: #800000;">${maxlogs}</span>
            <span style="color: #007800;">lcur</span>=<span style="color: #800000;">${maxlogs}</span>
            <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${lcur}</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
            <span style="color: #000000; font-weight: bold;">do</span>
                <span style="color: #007800;">lpre</span>=<span style="color: #800000;">${lcur}</span>
                <span style="color: #007800;">lcur</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #800000;">${lcur}</span> - <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
                <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span>.<span style="color: #800000;">${lcur}</span>.gz <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span>.<span style="color: #800000;">${lcur}</span>.gz <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span>.<span style="color: #800000;">${lpre}</span>.gz
            <span style="color: #000000; font-weight: bold;">done</span>
            <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span>.1
            <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span>.1 <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span>.1
&nbsp;
            logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;Starting backup from '<span style="color: #007800;">${src_ip}</span>'&quot;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;"># Sync internal shares and exclude usb shares</span>
            logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;Syncing internal shares...&quot;</span>
            rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'ssh -ax -c blowfish -l root'</span> <span style="color: #660033;">-aWvz</span> <span style="color: #660033;">--timeout</span>=<span style="color: #000000;">30</span> <span style="color: #660033;">--exclude</span>=<span style="color: #ff0000;">&quot;/usb[1-3]-1share1&quot;</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--stats</span> <span style="color: #800000;">${src_ip}</span>:<span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
            <span style="color: #007800;">JOB</span>=<span style="color: #007800;">$!</span>
            <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #800000;">${JOB}</span>
&nbsp;
            <span style="color: #666666; font-style: italic;"># Sync usb shares if connected</span>
            <span style="color: #000000; font-weight: bold;">for</span> x <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-ax</span> <span style="color: #660033;">-c</span> blowfish root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${src_ip}</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^d&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $9 }'</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">do</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`expr ${x} : '(usb[0-9]-[0-9]share[0-9])'`</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
                <span style="color: #000000; font-weight: bold;">then</span>
                    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/shares/<span style="color: #007800;">${x}</span>/&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
                        <span style="color: #000000; font-weight: bold;">then</span>
                        logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;Syncing <span style="color: #007800;">${x}</span>...&quot;</span>
                        rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'ssh -ax -c blowfish -l root'</span> <span style="color: #660033;">-aWvz</span> <span style="color: #660033;">--timeout</span>=<span style="color: #000000;">30</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--stats</span> <span style="color: #800000;">${src_ip}</span>:<span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${x}</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>shares<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${x}</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
                        <span style="color: #007800;">JOB</span>=<span style="color: #007800;">$!</span>
                        <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #800000;">${JOB}</span>
                    <span style="color: #000000; font-weight: bold;">fi</span>
                <span style="color: #000000; font-weight: bold;">fi</span>
            <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
            <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-2</span> <span style="color: #800000;">${logdir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${logfile}</span> <span style="color: #000000; font-weight: bold;">|</span> logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.info <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span>
        <span style="color: #000000; font-weight: bold;">else</span>
            logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;Load average on '<span style="color: #007800;">${src_ip}</span>' is <span style="color: #007800;">${loadavg}</span> - aborting&quot;</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;No access to '<span style="color: #007800;">${src_ip}</span>' - aborting&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${daemon}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;Backup finished&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">break</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;Waiting for cycle (<span style="color: #007800;">${waittime}</span> minutes)...&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #800000;">${waittime}</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">60</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
    <span style="color: #007800;">JOB</span>=<span style="color: #007800;">$!</span>
    <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #800000;">${JOB}</span>
    logger <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> daemon.notice <span style="color: #660033;">-t</span> <span style="color: #800000;">${logfile}</span> <span style="color: #ff0000;">&quot;Running cycle...&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Go back to old location</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #800000;">${pwd}</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kitara.nl/2010/03/13/how-to-backup-from-a-western-digital-sharespace-to-another-sharespace-v2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

