0

I want two way data sync between two CentOS based servers, so I installed Unison on both of my CentOS servers. I made a script file on root which runs unison and works fine, and syncs the files, when I run it from terminal. When I put that script in the crontab the sync simply does not work. My /etc/crontab is

*/1  *  *  *  * root sh /root/syncaaa.sh &>/root/unison-cron.log

And what crontab puts in the /root/unison-cron.log

Usage: unison [options]
    or unison root1 root2 [options]
    or unison profilename [options]

For a list of options, type "unison -help".
For a tutorial on basic usage, type "unison -doc tutorial".
For other documentation, type "unison -doc topics".

My unison.log file does not updated when run via cron, but only updates when runs directly via terminal. I checked in cron logs and syncaaa.sh file runs every miunte. Can anyone suggest me what I should do to debug it?

Note: My server 1 can login to server 2 without password, as I have set rsa keys in server2 authorized_keys.

> Update 1: I tried set -x in the script and it printed

+ chmod -R 0777 /home/user11/folder/
+ /usr/bin/unison
Usage: unison [options]
    or unison root1 root2 [options]
    or unison profilename [options]

For a list of options, type "unison -help".
For a tutorial on basic usage, type "unison -doc tutorial".
For other documentation, type "unison -doc topics"

and /usr/bin/unison command works fine on terminal

Mujtaba Haider
  • 131
  • 1
  • 7

2 Answers2

3

I solved the problem, and it was the HOME=/ in crontab, it should be the path where your .unison exists

So my crontab content now is

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/home/user1/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
*/1  *  *  *  * user1 sh syncaaa.sh &>unison-cron.log
Mujtaba Haider
  • 131
  • 1
  • 7
0

Add set -x at the top of the script, so it will print out each command before it runs it.
Then consult the log file to see what went wrong.

The error message you quoted from Unison means that the unison command didn't get the right number of arguments. The above approach will show you what command actually got run.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
  • it was printing `/usr/bin/unison` , and this command works on terminal. I also tried it with `/usr/bin/unison -batch default` – Mujtaba Haider Jan 22 '14 at 03:00
  • The `unison` command needs arguments: either the names of two directories to synchronize, or one profile file. Just running `unison` by itself will always give the output you showed. – Andrew Schulman Jan 22 '14 at 11:02