We'd like to use unison to sync two servers. From the command line and in bash files the following command works fine:
unison -batch /var/www/html/test ssh://host-2//var/www/html/test
Files are being synchronized and unison.log is being updated. so far so good.
in combination with a preference file, such as .unison/default.prf and simply executing unison from the command line as described here, things work fine too.
We've also installed incrond inotify cron daemon and it's running smooth. The following cron job is being executes just fine:
/var/www/html/test IN_MODIFY,IN_ATTRIB,IN_CREATE touch /root/test
/root/test is being updated every time I make changes to files in /var/www/html/test
So far so good! But the only things that don't work using the incrontab are:
/var/www/html/test IN_MODIFY,IN_ATTRIB,IN_CREATE unison
/var/www/html/test IN_MODIFY,IN_ATTRIB,IN_CREATE /usr/bin/unison
/var/www/html/test IN_MODIFY,IN_ATTRIB,IN_CREATE /usr/local/sbin/unison
/var/www/html/test IN_MODIFY,IN_ATTRIB,IN_CREATE unison -batch /var/www/html/test ssh://host-2//var/www/html/test
/var/www/html/test IN_MODIFY,IN_ATTRIB,IN_CREATE /usr/bin/unison -batch /var/www/html/test ssh://host-2//var/www/html/test
/var/www/html/test IN_MODIFY,IN_ATTRIB,IN_CREATE /usr/local/sbin/unison -batch /var/www/html/test ssh://host-2//var/www/html/test'
Nothing shows in the unison.log file, let alone updating the remote server.The following also doesn't output anything.
/var/www/html/test IN_MODIFY,IN_ATTRIB,IN_CREATE unison &> /root/test.log
/root/test.log is not even being created.
Another test using a batch file named sync.sh also doesn't work.
in the incrontab:
/var/www/html/test IN_MODIFY,IN_ATTRIB,IN_CREATE /root/sync.sh
and in sync.sh:
#!/bin/bash
touch /root/test
/usr/bin/unison -batch /var/www/html/test ssh://host-2//var/www/html/test
Again, /root/test is being touched just fine, meaning inofify works great every time I update a file in /var/www/html/test, but again no result at all from unison.
/var/log/cron looks like this:
May 21 06:33:44 Host-1 incrond[28339]: (root) CMD (sh /root/sync.sh)
and the unison.log is not being updated at all.
Conclusions:
inotifyworks fine, detects every change in the file system and executes a task, except for anyunisontask.unisonworks fine from command line and in batch, except when called by theincronddaemon.
Am I overlooking something?
unison.logonly gets updated if files were actually synchronized. Nothing gets logged if the check determines that there were no changes that needed synchronization, or if the check fails altogether, for whatever reason. Other information gets written to stdout/stderr, but does not end up in the log file by default unless you explicitly redirect it. – user149408 Mar 22 '22 at 14:15