busy-bee.net buzz buzz buzz goes the honeybee home | blog | links | about me

linux to an imac

2002-06-07 16:26 / ssh tunnels  »

ssh tunnels are yummy. Currently rsyncing both ways the mp3 directories on my nat'd usually-inaccessible-from-the-internet imac at home and firewalled machine at work. I have a gateway (thornhill) at home that I can ssh to - which can also reach the imac (marnie) - so something like this script below (adapted from here) does the trick handsomely:


#!/bin/sh
# licensed under the GNU GPL (http://www.fsf.org/licenses/gpl.html)

final=marnie
gw=thornhill
local_dir=/mnt/w2kdave/
remote_dir=/usr/local/share/mp3/
port=7778

function setup_tunnel() { 
    echo "Password on $gw"; 
    ssh -f -C -L $port:$final:22 $gw sleep 10; 
} 

function sync_marnie() { sync_from; sync_to; }

function sync_from() {  
    echo "Syncing from $final to local";  
    setup_tunnel; 
    echo "Local password"; 
    sudo rsync -vr --size-only -e "ssh -p $port" \
            dave@localhost:$remote_dir $local_dir; 
}

function sync_to()   { 
    echo "Syncing from local to $final"; 
    setup_tunnel; 
    echo "Password on $final"; 
    rsync -vr --size-only -e "ssh -p $port"  \ 
             $local_dir dave@localhost:$remote_dir; 
}


sync_marnie;
mod_perl -- Speed, Power, Scalability