0

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:

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

# binary file name
_unison=/usr/bin/unison

# 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
_rserver="node2.example.com"

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

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

prefer=newer
times=true
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?

Elijah Paul
  • 557
  • 1
  • 8
  • 19
  • Can you try to quote? like this? "${_unison} -batch -time -owner -group \"${p}\"" "ssh://${r}/${p}" – Danila Ladner Oct 10 '13 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 Oct 10 '13 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 Oct 10 '13 at 23:24
  • @DanilaLadner I did try to quote, but I received a 'directory not found' error. – Elijah Paul Oct 11 '13 at 03:14
  • @RSchulze Only occurred when the script is called in cron. Worked fine when executed via the command line. Strange. – Elijah Paul Oct 11 '13 at 03:16

1 Answers1

2

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.

Elijah Paul
  • 557
  • 1
  • 8
  • 19