#!/bin/bash ### Periodic unison sync with one or more machines ### # Copyright 2009 Ertug Karamatli # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . ### USAGE ### # 1. Create unison profile files in this format: ~/.unison/.prf # 2. Add the hosts you want to sync in HOSTS variable below. ### SETTINGS ### # Space seperated list of hosts (hostname or ip) HOSTS="laptop netbook" # Time to wait between syncing (seconds) WAIT=(60 * 5) ### TODO ### # Check hosts in list faster and if a host becomes online sync it first then wait for it (make it threaded) logger -s -t $0 "started." while [ 1 ]; do if [ -z "$(ps -e|grep unison)" ]; then for h in $HOSTS; do nc -z $h 22 if [ $? == 0 ]; then logger -s -t $0 "$h is online, starting unison..." unison -batch $h UNISON_RETCODE=$? if [ $UNISON_RETCODE == 0 ]; then logger -s -t $0 "synced $h successfully." else logger -s -t $0 "an error was occured while syncing $h, unison returned $UNISON_RETCODE" fi fi done else logger -s -t $0 "unison is already running, waiting it to end..." fi sleep $WAIT done