Synchronizing directories with Perl and SSH

For a while now I have been using ICQ both at home and at work. Instead of having two different copies of data or running ICQ remotely, I was simply copying all data files over between these two locations. rsync with scp were doing the job just fine. The problem emerged when I started to use ICQ on more than two machines (two machines in the office and one at home). I had to always figure out where is the latest copy of my data and distribute it from there to all the other locations. After doing it manually for just a couple of time bored me to death and I decided to write a script.

I started off with a very specific script that was only meant to copy my ICQ back and forth, but quickly realized that it can be generalized to copy any set of directories. So, here it is – sync_dirs.pl.

This script accepts and requires only one parameter – directory to synchronize. You can define a few shortcuts for frequently used directories inside the script. Locations are also defined inside the script. Since this piece of code uses Net::SSH and Net::SCP, the current limitation is that you must have ssh configured to authorize with keys, not passwords. The good news, is that you need only one location to be able to access all the others. The most recent copy of data will be copied over to this central location and from there distributed to all the other machines.

3 thoughts on “Synchronizing directories with Perl and SSH”


  1. i was facing the same problem untill i discover unison. it’s easy to setup and quick in action. although it does sync between two hosts, but i find that setting up one host as master solve it, just sync the client with the master before/after any changes.

    be careful that version of unison between two hosts should be the same.

Leave a Comment