Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sync a directory locally

Status
Not open for further replies.

AHinMaine

ISP
Nov 27, 2002
264
US
Anyone know of any stylish, self-contained ways of sync'ing a directory from one to another that doesn't involve installing rsync or any extra perl modules?

I tried using rdist which is already installed, but it oddly refuses to run as root. If I run:

Code:
rdist6 -R -p '/usr/local/bin/rdistd' -c alias localhost:~netdist/testing

as a non-root user, it works fine. If I run it as root, it fails with connection refused. I need it to run as root because I'm syncing up some config files. I need it to be somewhat self contained because this is a fairly heterogenous environment so I need something that'll work without having to go installing stuff on a variety of different machines.

--
Andy
 
Never mind... broke down and wrote a little something:

Code:
#!/bin/sh
#
# putdiff.sh
#
# Created: 2003/05/12 by Andy Harrison 
#
# this script was mainly written for root to move the distributed alias
# directory into the qmail/alias/ directory
#
# Usage: putdiff targetdir sourcedir
#
# $Id: putdiff.sh,v 1.5 2003/05/13 12:18:34 ajharrison Exp $

cwd=`pwd`
target_dir=$1
source_dir=${2:-.}
tmp_dir=${3:-/tmp}
cd "${cwd}/${target_dir}" || exit
find . -print | sort > "$tmp_dir/$$.target"
cd "${cwd}/${source_dir}" || exit
find . -print | sort > "$tmp_dir/$$.source"
cd $cwd
diff "$tmp_dir/$$.target" "$tmp_dir/$$.source" |
while read action file
    do
    case $action in     
        '<')  echo &quot;rm -rf ${cwd}/${target_dir}/$file&quot;
            rm -rf &quot;${cwd}${target_dir}/$file&quot; 
            ;;    
        '>')  echo &quot;cp -pr ${cwd}/${source_dir}/$file ${cwd}/${target_dir}/$file&quot;
            cp -pr &quot;${cwd}/${source_dir}/$file&quot; &quot;${cwd}/${target_dir}/$file&quot; 
            ;;  
    esac
    done
rm -rf &quot;$tmp_dir/$$.source&quot; &quot;$tmp_dir/$$.target&quot;

--
Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top