I'm new to unison, and am trying to use its options in a simple shell script, but they seem to be ignored when the script is executed, causing no changes to be synced between the two servers.

My shell script:

# set paths / dirs
_paths="/var/www/html/ \

# binary file name

# Log in to remote server without a password
source $HOME/.keychain/$HOSTNAME-sh

# server names 
# sync node1.example.com with rest of the servers in cluster

# sync it
for r in ${_rserver}
    for p in ${_paths}
            ${_unison} -batch -time -owner -group "${p}"  "ssh://${r}/${p}"

If i remove the -time -owner -group options, the script syncs changes made fine.

If i add the options to the ~/.unison/default.prf file instead then the script executes successfully. e.g.

# Unison preferences file

group = true
owner = true

However. Since I have different scripts being called by different cron jobs, I'd prefer to have the options stated in the scripts themselves as opposed to preference files.

Any suggestions on what I'm doing wrong?

  • Can you try to quote? like this? "${_unison} -batch -time -owner -group \"${p}\"" "ssh://${r}/${p}" Commented Oct 10, 2013 at 22:46
  • Might be useful to add a set -x to your script so you can see exactly what command is being executed. Are there any errors displayed? Maybe adjust the unison logging? My point is, get your script and unison to give you more information.
    – Zoredache
    Commented Oct 10, 2013 at 23:05
  • Does the problem always occur when you use unison in a script, or does it only occur when the script is called by cron?
    – RSchulze
    Commented Oct 10, 2013 at 23:24
  • @DanilaLadner I did try to quote, but I received a 'directory not found' error. Commented Oct 11, 2013 at 3:14
  • @RSchulze Only occurred when the script is called in cron. Worked fine when executed via the command line. Strange. Commented Oct 11, 2013 at 3:16

1 Answer 1


Looks like you have to place the unison options after defining the root directories:

Formatted like this: link to unison manual (RTFM!)

unison root1 root2 [options]

So my code should be:

${_unison} -batch "${p}"  "ssh://${r}/${p}" -times -owner -group

Once the options are placed here, the script executes without any errors.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .