Hi There,
Got a question for you bash experts out there
. I have a file (client_ip):
192.168.3.100 twantrd
192.168.3.101 johntrd
192.168.3.102 ricktrd
As you can see, it contains the ip address and hostname of the machine associated with it. I pretty much need a bash script that will ssh into each ip and grab files to be backed and store it back on the server under the appropriate hostname. So it's like:
Server A ---(ssh)---> 192.168.3.100:/home/RAID/
192.168.3.100 ---(rsync)---> Server A:/home/backup/twantrd/
Server A ---(ssh)---> 192.168.3.101:/home/RAID/
192.168.3.101 ---(rsync)---> Server A:/home/backup/johntrd/
etc...
I have no problem creating a for loop to iterate through the file and grab the IP's and ssh'ing into them. My big problem is how to rsync the data to the appropriate hostname folder on ServerA. My partial script is below. Please help if someone can!! I truly appreciate it!! Thanks!
#!/bin/sh
myserver="blah.twantrd.com"
dir="/home/backup/"
backupdir="/home/RAID"
clientip=`cat client_ip | egrep -v '^#' | awk '{print $1}'`
clienthost=`cat client_ip | egrep -v '^#' | awk '{print $2}'`
#
#This will rsync the client's data to the server
#
for ip in $clientip; do
$ssh $ip "(cd $backupdir; rsync -avz * $myserver:$dir)"
done
P.S Forgot, this is all done on the server side (Server A).
-twantrd