Using unison options in shell script

shell-scriptingsynchronizationunison

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?

Best Answer

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.

Related Topic