Ubuntu – Unison – Automatically Sync Computers


Is there a way two sync multiple computers (i.e. particular directories in the home folder) automatically using Unison? If not, is there an alternative that can do this? I'm not completely against opening Unison all the time and doing the sync manually, but when it opens you must select a profile, which corresponds to just one directory, so you have to sync each individually. Add to that, the IP address is dynamic, and therefore has to be edited. This is quite tedious, and it seems there should be a simpler way. Am I missing something? Is there a way to simplify this process (possibly a bash script)?

Best Answer

  • My suggestion would be to solve the problem of the dynamic IP (most routers have the concept of address reservation, that you can use to "fix" the IP of your computer). After that, you can use the command line version of unison:

    unison -auto -batch profilename 

    and you can add it to your login/logout scripts or as a cron job.

    If you still need to change the ip, you can use sed in a script:

    1. create a template file in ~/.unison, newprof.tmpl, like this:

      root = /home/romano/
      root = ssh://romano@MYIPHERE//home/romano/
      path = education
      path = research
    2. create the following script, call it sync_newprof:

      cd $HOME/.unison
      cat newprof.tmpl | sed s/MYIPHERE/$1 >! newprof.prf
      unison -auto -batch profilename

      basically, we create a profile file changing the MYIPHERE word with the script first argument

    3. now you can call it as


      and it will create the profile with the given IP and sync.

  • Related Question