File Distribution Using rsnyc

July 18, 2004

The following script is used to distribute account files to different computers using rsync over ssh. Of course, it is important to note that the computer that runs this script as a cron job is the only computer that account files should be edited on. This includes hiding or aliasing the "passwd" command from users on the other machines. Also, if you want the ssh login to work automagically, you'll have to setup ssh keys.

However, maybe somebody with a little more drive can write up a script to run on all machines and merge changed files.

# Smart File Distribution Script
# Distribute list of files to via rsync to a list of hosts if they have been modified locally
# each file to distribute
D_FILES="/etc/passwd /etc/shadow /etc/group /etc/gshadow";
# each server to distribute to
D_HOSTS="dp1 dp2 dp8";
# loop through each file
for D_FILE in $D_FILES; do
	# if the file exists
	if [ -e $DFILE ]; then
		# if update file is older than real file
		if [ $D_FILE -nt $D_FILE.lastupdate ]
			# update update file
			touch $D_FILE.lastupdate
			# distribute to each host
			for D_HOST in $D_HOSTS; do
				if [ $D_HOST != `hostname` ]
					#sync the file
					rsync -p -e ssh $D_FILE $D_HOST:$D_FILE
					echo "Distributing $D_FILE to $D_HOST"
		echo "File $D_FILE doesn't even exist!"

Related Posts