<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'My bash script for syncing folders between two or three computers' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'My bash script for syncing folders between two or three computers' posted on the 'LINUX programming' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 25 May 2013 08:55:51 -0700</pubDate>
    <lastBuildDate>Sat, 25 May 2013 08:55:51 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>My bash script for syncing folders between two or three computers</title>
      <link>http://www.programmersheaven.com/mb/Linux/421619/421619/my-bash-script-for-syncing-folders-between-two-or-three-computers/</link>
      <description>I have two desktops and a laptop. I copied my music into each of them from my flash drive, but since then I have added music from various places and they got badly out of sync. So I decided to use rsync and create a script to run once a month or so. I hope someone finds it useful.&lt;br /&gt;
&lt;br /&gt;
 The main problem is that it makes me enter my password five times. I'm trying to learn expect so I can automate that process, if any one can help me with that I would appreciate it. If you have any other improvements, such as making it capable of handling any number of computers, or reducing the amount of code, I would like to hear them as well. &lt;br /&gt;
&lt;br /&gt;
I tried using RSYNC_PASSWORD, but apparently it and --password-file no longer work. &lt;br /&gt;
&lt;br /&gt;
The script runs on mark, my fastest computer. I tried to use it in as many exchanges as possible and my old laptop, robby, in the least amount of exchanges possible.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
#!/bin/bash

# sync -- uses rsync to sync the music folders of two or three computers #

# philipk88
# 2-8-11


#### Functions ####


main()
{
   read -p 'What is the ip address of Marvin?&amp;gt;' marvin
   read -p 'Is Robby connected to the network?[N/y]&amp;gt;' robbyExist
   if [ $robbyExist = y ]
   then
      read -p 'What is the ip address of Robby?&amp;gt;' robby
      remotefile="$marvin:$marvinPath"
      toMark
      fromMark
      remotefile="$robby:$robbyPath"
      toMark
      fromMark
      remotefile="$marvin:$marvinPath"
      fromMark
      echo "Copying is done"
      exit
   else
      remotefile="$marvin:$marvinPath"
      toMark
      fromMark
      echo "Copying is done"
      exit
   fi
}
      
   
# Displays a pretentious welcome message #
welcome()
{
   echo " "
   echo " "
   echo '#############################################'
   echo '#                                           #'
   echo '#  Welcome to your music syncing program!!  #'
   echo '#       Let the synchronization begin!       #'
   echo '#                                           #'
   echo '#############################################'
   echo " "
   echo " "
   return
}

# Copies the files that only exist on the remote computer to the local file #
toMark()
{
   rsync -vzr -e ssh philip@$remotefile  /home/philip/Music  
   return
}

# Copies the files that only exist locally to the remote computer #
fromMark()
{
   rsync -vzr /home/philip/Music/ -e ssh philip@$remotefile  
   return
}


#### Program ####


## Assign Variables ##

marvin=192.168.2.2
marvinPath=/home/philip/arch-share/music/
robby=192.168.2.4
robbyPath=/home/philip/music/

## Display a welcome message ##

welcome

## Call main and get to work ##

main
  

#### End ####
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/Linux/421619/421619/my-bash-script-for-syncing-folders-between-two-or-three-computers/</guid>
      <pubDate>Wed, 09 Feb 2011 16:25:42 -0700</pubDate>
      <category>LINUX programming</category>
    </item>
  </channel>
</rss>