A life without cause is a life without effect.
- Barbarella
#!/bin/bash
#
# 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 ]
then
# update update file
touch $D_FILE.lastupdate
# distribute to each host
for D_HOST in $D_HOSTS; do
if [ $D_HOST != `hostname` ]
then
#sync the file
rsync -p -e ssh $D_FILE $D_HOST:$D_FILE
echo "Distributing $D_FILE to $D_HOST"
fi
done
fi
else
echo "File $D_FILE doesn't even exist!"
fi
done