<?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>Lennart&#039;s weblog &#187; script</title>
	<atom:link href="http://blog.karssen.org/tag/script/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.karssen.org</link>
	<description>Open source, computers, Africa and other more (or less) interesting stuff.</description>
	<lastBuildDate>Thu, 02 Feb 2012 19:15:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Using Plugwise adapters with Linux</title>
		<link>http://blog.karssen.org/2011/11/20/using-plugwise-adapters-with-linux/</link>
		<comments>http://blog.karssen.org/2011/11/20/using-plugwise-adapters-with-linux/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 20:53:08 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=214</guid>
		<description><![CDATA[Yesterday I received a small package I had ordered: the Plugwise Home Start kit. According to the box it is an energy management and control system. The idea is that you insert a sort of adaptor between a power socket and a device and using the Plugwise Source software you can monitor the power usage [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I received a small package I had ordered: the <a href="http://www.plugwise.com">Plugwise</a> <a href="http://www.plugwise.com/idplugtype-f/home-start">Home Start</a> kit. According to the box it is an energy management and control system. The idea is that you insert a sort of adaptor between a power socket and a device and using the Plugwise Source software you can monitor the power usage of the device. Furthermore, you can use the software to create schedule to turn the device on and off at a specific time.</p>
<p>The package contains the following:</p>
<ul>
<li>a USB adapter (called the Stick)</li>
<li>a Circle+, the master adaptor that keeps track of the other devices in the network
<li>a Circle, the regular members of the Plugwise network
</ul>
<p>The Circles communicate to each other using the ZigBee protocol in the 2.4GHz range. According to the documentation, the range of each Circle is about 5m.</p>
<p>Unfortunately the Source software only runs on windows. Luckily some people have already analysed the protocol and written some software to control the Plugwise devices (see links below).</p>
<h2>First steps</h2>
<p>  Plugging the USB dongle in gives the following output in <code>/var/log/syslog</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">Nov 19 12:20:37 barabas kernel: [  182.855742] usb 1-1.6.1.1.3: new full speed USB device number 14 using ehci_hcd
Nov 19 12:20:37 barabas mtp-probe: checking bus 1, device 14: &quot;/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.6/1-1.6.1/1-1.6.1.1/1-1.6.1.1.3&quot;
Nov 19 12:20:37 barabas mtp-probe: bus: 1, device: 14 was not an MTP device
Nov 19 12:20:37 barabas kernel: [  183.169370] usbcore: registered new interface driver usbserial
Nov 19 12:20:37 barabas kernel: [  183.169389] USB Serial support registered for generic
Nov 19 12:20:37 barabas kernel: [  183.169431] usbcore: registered new interface driver usbserial_generic
Nov 19 12:20:37 barabas kernel: [  183.169434] usbserial: USB Serial Driver core
Nov 19 12:20:37 barabas kernel: [  183.171310] USB Serial support registered for FTDI USB Serial Device
Nov 19 12:20:37 barabas kernel: [  183.171552] ftdi_sio 1-1.6.1.1.3:1.0: FTDI USB Serial Device converter detected
Nov 19 12:20:37 barabas kernel: [  183.171588] usb 1-1.6.1.1.3: Detected FT232RL
Nov 19 12:20:37 barabas kernel: [  183.171591] usb 1-1.6.1.1.3: Number of endpoints 2
Nov 19 12:20:37 barabas kernel: [  183.171595] usb 1-1.6.1.1.3: Endpoint 1 MaxPacketSize 64
Nov 19 12:20:37 barabas kernel: [  183.171598] usb 1-1.6.1.1.3: Endpoint 2 MaxPacketSize 64
Nov 19 12:20:37 barabas kernel: [  183.171602] usb 1-1.6.1.1.3: Setting MaxPacketSize 64
Nov 19 12:20:37 barabas kernel: [  183.171975] usb 1-1.6.1.1.3: FTDI USB Serial Device converter now attached to ttyUSB0
Nov 19 12:20:37 barabas kernel: [  183.171998] usbcore: registered new interface driver ftdi_sio
Nov 19 12:20:37 barabas kernel: [  183.172002] ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver
Nov 19 12:20:37 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) opening serial port...
Nov 19 12:20:49 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) closing serial port...
Nov 19 12:20:49 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) serial port closed
Nov 19 12:20:49 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) opening serial port...
Nov 19 12:20:55 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) closing serial port...
Nov 19 12:20:55 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) serial port closed</pre></div></div>

<p><code>lsusb</code> gives:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">Bus 001 Device 014: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC</pre></div></div>

<p>I couldn&#8217;t get the pairing to work under Linux (with the PlugwiseOnLinux scripts), Even though I corrected the MAC address in the python code. I then tried it in Windows where I failed at first also. After resetting the Circle+ and the Circle (removing/inserting them into the power outlet with 3 second intervals, as mentioned in the FAW on the plugwise website) I managed to pair the Circles. Looking back, I think I didn&#8217;t wait long enough for the pairing to work under Linux. During the trials in Windows I noticed that the pairing can take up to about 5 minutes&#8230;</p>
<p>Back in Linux I used python-plugwise (see links below) to turn the Circles on and off, e.g. this is how I turn my Circle+ off (note that I am a member of the dialout group, which is needed to communicate with <code>/dev/ttyUSB0</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ plugwise_util <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0 <span style="color: #660033;">-m</span> 000D6F0000B1C117 <span style="color: #660033;">-s</span> off</pre></div></div>

<p>This is what I want! The only minor downside of python-plugwise is that it depends on the crcmod python library, which apparently is not package for Debian/Ubuntu. So installing using the python-setup framework as mentioned in the README is necessary.</p>
<p>Reading out the current power usage of my Circle works also:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ plugwise_util <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0 <span style="color: #660033;">-m</span> 000D6F0000B85134 <span style="color: #660033;">-p</span>
power usage: 2.27W</pre></div></div>

<p>So, no that it works, what am I going to do with the Plugwise modules? I&#8217;m going to use them in my backup scripts to switch the power to my external hard drives.</p>
<h2> Making a .deb</h2>
<p>I used <code>checkinstall</code> to make a package of python-plugwise. In a working directory, first check out the source code of python-plugwise using mercurial, as mentioned on the web site:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ hg clone https:<span style="color: #000000; font-weight: bold;">//</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>hadara<span style="color: #000000; font-weight: bold;">/</span>python-plugwise</pre></div></div>

<p>Then run <code>checkinstall</code> and don&#8217;t forget to fill in the details correctly. For example, the package name is &#8216;python&#8217; by default, which you definitely don&#8217;t want, since that would overwrite Ubuntu&#8217;s default &#8216;python&#8217; package. Also make sure that you remove the crcmod python library if you installed python-plugwise before, otherwise it won&#8217;t get packaged. The output below shows the final values, after I changed them.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> checkinstall <span style="color: #660033;">-D</span> python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span>
&nbsp;
checkinstall 1.6.2, Copyright <span style="color: #000000;">2009</span> Felipe Eduardo Sanchez Diaz Duran
	      This software is released under the GNU GPL.
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">*****************************************</span>
<span style="color: #000000; font-weight: bold;">****</span> Debian package creation selected <span style="color: #000000; font-weight: bold;">***</span>
<span style="color: #000000; font-weight: bold;">*****************************************</span>
&nbsp;
This package will be built according to these values:
&nbsp;
<span style="color: #000000;">0</span> -  Maintainer: <span style="color: #7a0874; font-weight: bold;">&#91;</span> lennart<span style="color: #000000; font-weight: bold;">@</span>karssen.org <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">1</span> -  Summary: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise is used to control the Plugwise power switches <span style="color: #c20cb9; font-weight: bold;">as</span> well <span style="color: #c20cb9; font-weight: bold;">as</span> <span style="color: #c20cb9; font-weight: bold;">read</span> out information on power usage. <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">2</span> -  Name:    <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">3</span> -  Version: <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">0.2</span>-hg-<span style="color: #000000;">20111120</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">4</span> -  Release: <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">5</span> -  License: <span style="color: #7a0874; font-weight: bold;">&#91;</span> GPL <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">6</span> -  Group:   <span style="color: #7a0874; font-weight: bold;">&#91;</span> checkinstall <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">7</span> -  Architecture: <span style="color: #7a0874; font-weight: bold;">&#91;</span> amd64 <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">8</span> -  Source location: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">9</span> -  Alternate <span style="color: #7a0874; font-weight: bold;">source</span> location: <span style="color: #7a0874; font-weight: bold;">&#91;</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">10</span> - Requires: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">11</span> - Provides: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">12</span> - Conflicts: <span style="color: #7a0874; font-weight: bold;">&#91;</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">13</span> - Replaces: <span style="color: #7a0874; font-weight: bold;">&#91;</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Enter a number to change any of them or press ENTER to <span style="color: #7a0874; font-weight: bold;">continue</span>:</pre></div></div>

<p>You can check the contents of the package to make sure the crcmod<br />
files are included using <code>dpkg</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">--contents</span> python-plugwise_0.2-hg-<span style="color: #000000;">20111120</span>-<span style="color: #000000;">1</span>_amd64.deb</pre></div></div>

<p>An idea for later: make an SNMP module that calls <i>plugwise_util</i> to get the power usage so that I can monitor the power usage of a device using Cacti.</p>
<h2>Links</h2>
<ul>
<li>The software I use: <a href="https://bitbucket.org/hadara/python-plugwise/overview">python-plugwise</a></li>
<li><a href="http://www.maartendamen.com/tag/plugwise/">The blog of Maarten Damen</a>, the guy that seems to have been the first one to analyse the plugwise protocol</li>
<li><a href="http://roheve.wordpress.com/tag/plugwise/">Another blog, also with info on the protocol</a></li>
<li><a href="https://github.com/hackstuces/PlugwiseOnLinux.git">PlugwiseOnLinux</a>, a set of python scripts for pairing Plugwise and the Circles. Did not work with me at first, didn&#8217;t retry later</li>
<li><a href="http://wordpress.dirkengels.com/tag/plugweb-2/">PlugWeb</a>, a PHP interface, for those wanting to control their Plugwise network via a web interface</li>
<li>According to its website <a href="http://www.domotiga.nl/">DomotiGa</a> can also control Plugwise devices, but I haven&#8217;t tried it (yet)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/11/20/using-plugwise-adapters-with-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedding album art in FLAC files</title>
		<link>http://blog.karssen.org/2011/07/31/embedding-album-art-in-flac-files/</link>
		<comments>http://blog.karssen.org/2011/07/31/embedding-album-art-in-flac-files/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 18:44:53 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=149</guid>
		<description><![CDATA[I recently wanted to add cover art to my collection of FLAC-encoded audio files. I wrote the following simple script to help me automate the process. Running this script in a given directory (I group my music in directories per artist, followed by a subdirectory for each album) with the name of the album art [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wanted to add cover art to my collection of FLAC-encoded audio files. I wrote the following simple script to help me automate the process. Running this script in a given directory (I group my music in directories per artist, followed by a subdirectory for each album) with the name of the album art image file name as argument then automatically embeds the image in the FLAC/Vorbis tag.</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: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This script embeds a given image (usually .jpg) as album art in the</span>
<span style="color: #666666; font-style: italic;"># FLAC files in the present directory (and its subdirectories).</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Time-stamp: &lt;2011-07-31 20:43:23 (lennart)&gt;</span>
&nbsp;
<span style="color: #007800;">coverart</span>=<span style="color: #007800;">$1</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.flac&quot;</span> <span style="color: #660033;">-print0</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-0</span> metaflac <span style="color: #660033;">--import-picture-from</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$coverart</span>&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/07/31/embedding-album-art-in-flac-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using rsync to backup to a remote Synology Diskstation</title>
		<link>http://blog.karssen.org/2011/02/06/using-rsync-to-backup-to-a-remote-synology-diskstation/</link>
		<comments>http://blog.karssen.org/2011/02/06/using-rsync-to-backup-to-a-remote-synology-diskstation/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 20:54:36 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=108</guid>
		<description><![CDATA[I recently bought a NAS, a Synology DiskStation DS211j and stuffed two 1TB disks in it. I configured the disks to be in RAID 1 (mirrored) in case one of them decides to die. I then brought the NAS to a family member&#8217;s house and installed it there. Now she uses it to back up [...]]]></description>
			<content:encoded><![CDATA[<p>I recently bought a NAS, a <a href="http://www.synology.com/nld/products/DS211j/index.php"> Synology DiskStation DS211j</a> and stuffed two 1TB disks in it. I configured the disks to be in RAID 1 (mirrored) in case one of them decides to die. I then brought the NAS to a family member&#8217;s house and installed it there. Now she uses it to back up her important files (and as a storage tank for music and videos).</p>
<p>The good thing for me is that I can now make off-site backups of my home directories. I configured the DS211j to accept SSH connections so that I can log into it (as user admin or root). I used the web interface to create a directory for my backups (which appeared to be <code>/volume1/BackupLennart</code> after logging in with SSH).</p>
<p>After making a hole in her firewall that allowed me to connect to the DS211j, I created a backup script in <code>/etc/cron.daily</code> with the following contents:</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: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This script makes a backup of my home dirs to a Synology DiskStation at</span>
<span style="color: #666666; font-style: italic;"># another location. I use LVM for my /home, so I make a snapshot first and</span>
<span style="color: #666666; font-style: italic;"># backup from there.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Time-stamp: &lt;2011-02-06 21:30:14 (lennart)&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">###############################</span>
<span style="color: #666666; font-style: italic;"># Some settings</span>
<span style="color: #666666; font-style: italic;">###############################</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># LVM options</span>
<span style="color: #007800;">VG</span>=raidvg01
<span style="color: #007800;">LV</span>=home
<span style="color: #007800;">MNTDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>home_rsync_snapshot<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># rsync options</span>
<span style="color: #007800;">DEST</span>=root<span style="color: #000000; font-weight: bold;">@</span>remote-machine.example.com:<span style="color: #000000; font-weight: bold;">/</span>volume1<span style="color: #000000; font-weight: bold;">/</span>BackupLennart<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">SRC</span>=<span style="color: #800000;">${MNTDIR}</span><span style="color: #000000; font-weight: bold;">/*</span>
<span style="color: #007800;">OPTIONS</span>=<span style="color: #ff0000;">&quot;-e ssh --delete --progress -azvhHS --numeric-ids --delete-excluded &quot;</span>
<span style="color: #007800;">EXCLUSIONS</span>=<span style="color: #ff0000;">&quot;--exclude lost+found --exclude .thumbnails --exclude .gvfs --exclude .cache --exclude Cache&quot;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">###############################</span>
<span style="color: #666666; font-style: italic;"># The real work</span>
<span style="color: #666666; font-style: italic;">###############################</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create the LVM snapshot</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: #007800;">$MNTDIR</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;"># If the snapshot directory exists, another backup process may be</span>
    <span style="color: #666666; font-style: italic;"># running</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MNTDIR</span> already exists! Another backup still running?&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #660033;">-1</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #666666; font-style: italic;"># Let's make snapshots</span>
    <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$MNTDIR</span>
    lvcreate <span style="color: #660033;">-L5G</span> <span style="color: #660033;">-s</span> <span style="color: #660033;">-n</span> snap<span style="color: #007800;">$LV</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$VG</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$LV</span>
    <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$VG</span><span style="color: #000000; font-weight: bold;">/</span>snap<span style="color: #007800;">$LV</span> <span style="color: #007800;">$MNTDIR</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># Do the actual backup</span>
rsync <span style="color: #007800;">$OPTIONS</span> <span style="color: #007800;">$EXCLUSIONS</span> <span style="color: #007800;">$SRC</span> <span style="color: #007800;">$DEST</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Remove the LVM snapshot</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: #007800;">$MNTDIR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$VG</span><span style="color: #000000; font-weight: bold;">/</span>snap<span style="color: #007800;">$LV</span>
    lvremove <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$VG</span><span style="color: #000000; font-weight: bold;">/</span>snap<span style="color: #007800;">$LV</span>
    <span style="color: #c20cb9; font-weight: bold;">rmdir</span> <span style="color: #007800;">$MNTDIR</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MNTDIR</span> does not exist!&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #660033;">-1</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Let&#8217;s walk through it: in the first section I configure several variables. Since I use LVM on my server, I can use it to make a snapshot of my /home partition. The LVM volume group I use is called &#8216;raidvg01&#8242;. Withing that VG my /home partition resides in a logical volume called &#8216;home&#8217;. The variable <code>MNTDIR</code> is the place where I mount the LVM snapshot of &#8216;home&#8217;.</p>
<p>The rsync options are quite straight forward. Check the rsync man page to find out what they mean. Note that I used the <code>--numeric-ids</code> option because the DS211j doesn&#8217;t have the same users as my server and this way all ownerships will still be correct if I ever need to restore from this backup.</p>
<p>In the section called &#8220;The real work&#8221; I first create the <code>MNTDIR</code> directory. Subsequently I create the LVM snapshot and mount it. After this the rsync backup can be run and finally I unmount the snapshot and remove it, followed by the removal of the <code>MNTDIR</code>.</p>
<p>Since the script is placed in <code>/etc/cron.daily</code> it will be executed every day. Since we use SSH to connect to the remote DS211j I set up SSH key access without a password. <a href="http://www.debian-administration.org/article/SSH_with_authentication_key_instead_of_password">This Debian howto</a> will tell you how to set that up.</p>
<p>The only thing missing in this setup is that the backups are not stored in an encrypted form on the remote NAS, but for now this is good enough. I can&#8217;t wait until the network bandwidth on both sides of this backup connection get so fast (and affordable) that I can easily sync my music as well. Right now uploads are so slow that I hardly dare to include those. I know that I shouldn&#8217;t complain since the Netherlands has one of the highest broadband penetrations in the world, but, hey, don&#8217;t you just always want a little more, just like Oliver Twist?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/02/06/using-rsync-to-backup-to-a-remote-synology-diskstation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Script to tunnel RDP connections through stepping stone server using SSH</title>
		<link>http://blog.karssen.org/2010/02/10/script-to-tunnel-rdp-connections-through-a-stepping-stone-server-using-ssh/</link>
		<comments>http://blog.karssen.org/2010/02/10/script-to-tunnel-rdp-connections-through-a-stepping-stone-server-using-ssh/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 13:12:05 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=57</guid>
		<description><![CDATA[In order to connect to the servers at work we need to connect through a stepping stone host (via SSH). Since some of the servers are MS Windows machines which can be managed via the Remote Desktop Protocol (RDP), this traffic needs to be tunneled over SSH as well. I wrote the following bash script [...]]]></description>
			<content:encoded><![CDATA[<p>In order to connect to the servers at work we need to connect through a stepping stone host (via SSH). Since some of the servers are MS Windows machines which can be managed via the Remote Desktop Protocol (RDP), this traffic needs to be tunneled over SSH as well.<br />
I wrote the following bash script to automate setting up the tunnel. It sets some default variables and then looks for an available port between 1234 and 1254 (chosen completely arbitrarily) and uses it for the tunnel. Then it uses the <tt>rdesktop</tt> program to start the RDP connection.</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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This script makes an ssh tunnel to a stepping stone server</span>
<span style="color: #666666; font-style: italic;"># and uses it to start an rdesktop connection to the machine </span>
<span style="color: #666666; font-style: italic;"># given as the first argument of the script. </span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># (C) L.C. Karssen</span>
<span style="color: #666666; font-style: italic;"># $Id: winremote.sh,v 1.14 2010/02/10 13:03:08 lennart Exp $</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># User-configurable variables</span>
<span style="color: #007800;">ssh_username</span>=your_steppingstone_username_here
<span style="color: #007800;">steppingstone</span>=steppingstone.your_company.com
<span style="color: #007800;">rdesktop_username</span>=your_windows_username_here
<span style="color: #007800;">rdesktop_domain</span>=your_windows_domain_here
<span style="color: #007800;">rdesktop_opts</span>=<span style="color: #ff0000;">&quot;-z -g 1024x768 -a 16&quot;</span>
<span style="color: #007800;">rdesktop_port</span>=<span style="color: #000000;">3389</span> <span style="color: #666666; font-style: italic;"># This is the standard MS rdesktop port</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># For ordinary users it should not be necessary to change anything below this line. </span>
<span style="color: #666666; font-style: italic;"># Some functions:</span>
usage<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;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOF
Usage:
    $program [options] rdesktop_hostname 
&nbsp;
Make a remote desktop connection through an SSH tunnel.
&nbsp;
Options: 
    -h, --help                                   print this help message
    -s, --steppingstone steppingstone_hostname   set other stepping stone host
                                                   (default: $steppingstone)
    -t, --timeout sec                            set timeout (default: 1)
    -v, --verbose                                verbose output
     --version                                   print version
&nbsp;
Note that some customisations need to be made in the first few lines of this 
script (e.g. user names and other defaults)
EOF</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">program</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>
&nbsp;
<span style="color: #666666; font-style: italic;"># Command line option parsing. Shift all options </span>
<span style="color: #007800;">verbose</span>=
<span style="color: #007800;">timeout</span>=<span style="color: #000000;">1</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span> 
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">in</span>
	<span style="color: #660033;">-v</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #660033;">--verbose</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #660033;">--debug</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> 
	    <span style="color: #007800;">verbose</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
	    <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #660033;">--version</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
	    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'$Revision: 1.14 $'</span>
	    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
	    <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #660033;">-t</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #660033;">--timeout</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> 
	    <span style="color: #7a0874; font-weight: bold;">shift</span>
	    <span style="color: #007800;">timeout</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
	   <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$timeout</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	       <span style="color: #007800;">timeout</span>=<span style="color: #000000;">1</span>
	   <span style="color: #000000; font-weight: bold;">fi</span>
	   <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$verbose</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	       <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Timeout set to <span style="color: #007800;">$timeout</span>&quot;</span>
	   <span style="color: #000000; font-weight: bold;">fi</span>
	   <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #660033;">--steppingstone</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> 
	   <span style="color: #7a0874; font-weight: bold;">shift</span>
	   <span style="color: #007800;">steppingstone</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
	   <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$verbose</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	       <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Steppingstone server is <span style="color: #007800;">$steppingstone</span>&quot;</span>
	   <span style="color: #000000; font-weight: bold;">fi</span>
	   <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #660033;">-h</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #660033;">--help</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> 
	   usage
	   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
	   <span style="color: #000000; font-weight: bold;">;;</span>
	-<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> 
	   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$0: invalid option $1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
 	   usage
	   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
	   <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> 
	   <span style="color: #7a0874; font-weight: bold;">break</span>
	   <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Server name (as seen on the steppingstone) that we want to connect to:</span>
<span style="color: #007800;">rdesktop_server</span>=<span style="color: #007800;">$1</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">################### Config done, let's get to work ########################</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Simple usage description</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;">$rdesktop_server</span>&quot;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error: No rdesktop host given&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
    usage
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Find a free port on the local machine that we can use to connect through</span>
<span style="color: #007800;">min_port</span>=<span style="color: #000000;">1234</span>
<span style="color: #007800;">max_port</span>=<span style="color: #000000;">1254</span>
<span style="color: #007800;">used_ports</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-tan</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> 127.0.0.1 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> -g<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$verbose</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Used ports are: <span style="color: #007800;">${used_ports[@]}</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># In the next line we first print the $used_ports as an array, but with </span>
<span style="color: #666666; font-style: italic;"># each port on a single line. This is then piped to an awk script that </span>
<span style="color: #666666; font-style: italic;"># puts all the values in an array and subsequently walks through all ports </span>
<span style="color: #666666; font-style: italic;"># from $min_port to $max_port in order to find the first port that is not </span>
<span style="color: #666666; font-style: italic;"># in the array. This port is printed.</span>
<span style="color: #007800;">local_port</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;%i<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #800000;">${used_ports[@]}</span> <span style="color: #000000; font-weight: bold;">|</span> \
    <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-v</span> <span style="color: #007800;">minp</span>=<span style="color: #007800;">$min_port</span> <span style="color: #660033;">-v</span> <span style="color: #007800;">maxp</span>=<span style="color: #007800;">$max_port</span> \
    <span style="color: #ff0000;">'{ array[$1]=1 } END { for (i=minp; i&lt;=maxp; i++) { if (i in array) continue; else { print i; break } } }'</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;">$local_port</span>&quot;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error: No ports free! Exiting...&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">2</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$verbose</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Selected port was: <span style="color: #007800;">$local_port</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create tunnel:</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$verbose</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Creating SSH tunnel...&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #007800;">ssh_opts</span>=<span style="color: #ff0000;">&quot;-f -N -L&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #007800;">$ssh_opts</span> <span style="color: #007800;">$local_port</span>:<span style="color: #007800;">$rdesktop_server</span>:<span style="color: #007800;">$rdesktop_port</span> \
    <span style="color: #007800;">$ssh_username</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$steppingstone</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Allow the ssh tunnel to be established</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #007800;">$timeout</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Abort if tunnel has not been established</span>
<span style="color: #007800;">pidof_ssh</span>=<span style="color: #000000; font-weight: bold;">`</span>pgrep <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;ssh <span style="color: #007800;">$ssh_opts</span> <span style="color: #007800;">$local_port</span>&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;">$pidof_ssh</span>&quot;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error: Timeout while establishing tunnel&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Exiting...&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">3</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Make rdesktop connection</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$verbose</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Opening Remote desktop connection to <span style="color: #007800;">$rdesktop_server</span>...&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
rdesktop <span style="color: #007800;">$rdesktop_opts</span> <span style="color: #660033;">-u</span> <span style="color: #007800;">$rdesktop_username</span> <span style="color: #660033;">-p</span> - \
    <span style="color: #660033;">-d</span> <span style="color: #007800;">$rdesktop_domain</span> localhost:<span style="color: #007800;">$local_port</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Clean up tunnel</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$verbose</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Cleaning up SSH tunnel with pid <span style="color: #007800;">$pidof_ssh</span> and local port <span style="color: #007800;">$local_port</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #007800;">$pidof_ssh</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2010/02/10/script-to-tunnel-rdp-connections-through-a-stepping-stone-server-using-ssh/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

