unison+inotifywaitで全自動同期

inotifywaitを使えばフォルダ変更の通知をイベントとして受け取れると聞いたので
フォルダに変更があれば自動でunisonが走るプログラムを書いてみた.

inotifywaitはubuntuの場合

sudo apt-get install inotify-tools

で手に入る.

あとは,/usr/local/bin/syncronizerなどに

#!/bin/bash                                                                                   
root1=local_directory
root2=ssh://host_name//remote_directory

while inotifywait -r -e create -e delete -e close_write -e move $root1; do
  unison $root1 $root2 -silent -batch -owner -group -backups -times -prefer newer
  date
done

と書いておき,このプログラムを裏で動かせば完了である.