Sync files and directories using Rsync, Zenity, SSH and cron

My systems as performed: Ubuntu 10.04 Localhost, Debian 6.03 Remotehost

1) Configure your systems for an SSH public/private keypair (see ref: 1 below)

2) configure local user's bash environment: (see ref: 5)

edit ~/.bashrc and add this line:

xhost local:your_localuser > /dev/null

3) create rsync script:


# test if the ssh connection can be made
ssh -q -i /directory_to_ssh_keys/your-rsync-key your_remotehost_user@your_remotehost_ip exit
if [ $? = 0 ]      
((rsync -av --progress --omit-dir-times -e "ssh -i /directory_to_ssh_keys/your-rsync-key" "/your_local_directory/photos/" "your_remotehost_user@your_remotehost_ip:/your_remotehost_directory/familyphotos" | zenity --auto-kill --progress --pulsate --text="Wait while I sync the photo folder.. Don't move any photos or use Picassa ....") &

#Start a loop testing if zenity is running, and if not kill rsync (see ref: 2)
while [ $RUNNING -eq 0 ]
if [ -z "$(pidof zenity)" ]
	pkill -9 rsync
zenity --warning --text "Backup server not available";echo $?

4) Create your crontab entry

using crontab -e, my example is an hourly sync:

# m h  dom mon dow   command
0 * * * * export DISPLAY=:0.0 && /directory_of _your_script/


1. Secure your SSH server with Public/Private key authentification | Debian/Ubuntu Tips & Tricks

2. Bug #220656 in zenity (Ubuntu): “zenity --progress cancel button doesn't return a value”

3. Wget and zenity --progress - Page 2 - Ubuntu Forums

4. A complete zenity dialog examples 2 » Linux by Examples

5. Linux etc. » Blog Archive » Running X apps (like zenity) from crontab (solving “cannot open display” problem)

6. HowTo make cron run GUI applications [Archive] - Ubuntu Forums

7. [all variants] Two-way synchronizing , rsync? - Ubuntu Forums

8. Do more backups - David Picard


James Horvath Gooey Website
James Horvath Gooey Oooey