Tuesday, January 26, 2010

Syncing Folders Between two Machines Running Linux

There was a thread in th #! forums that peaked my interest. A user wanted to be able to easily sync the music folder on a laptop with that of a desktop. I thought it was an awesome idea. Here is my solution:

install sshfs on the laptop

sudo aptitude install sshfs

install openssh-server and client on the desktop if not already there.

sudo aptitude install openssh-server openssh-client

Create a temporary directory for mounting the desktops music folder on the laptop. I created one named "desk_music"

Now you can use this script to sync your music!

#!/bin/bash



count=$(ping -c 4 192.168.1.100 | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
    echo "failure"


else 
    echo "we're in business" &
    sshfs chelsea@192.168.1.100:/home/chelsea/Music /home/monkeybritt/desk_music;
    cp -rnv /home/monkeybritt/desk_music/* /home/monkeybritt/Music;
    fusermount -u /home/monkeybritt/desk_music
  fi


using cp with the -rnv argument tells it to copy recursively and to skip existing files, and the v (verbose) will show progress.

0 comments: