2

I am trying to use rsync to synchronise remote files with local server. It works great but I want to do it on multiple remote servers to sync with on daily basis.

sshpass -p "xyz" rsync -avz lanein1@xx.xxx.xxx.xxx:BrandStIN/ /home/lanein1/BrandStIN/
sshpass -p "xyz" rsync -avz lanein1@yy.yyy.yyy.yyy:MarySt/ /home/lanein1/MarySt/
sshpass -p "xyz" rsync -avz lanein1@aa.aaa.aaa.aaa:IWM/ /home/lanein1/IWM/

I have 10 IP numbers which I have to rsync daily for checking , How I can do that by using BASH script. So that I can automate that task by using cron. I want BASH script only.

I am struck here.I have all the Ip addresses in a text file and dont know how to call the file on rsync with their passwords.

#!/bin/bash
# Program name: rsyncall.sh
date
cat /path/to/IP.txt |  while read output
do........
  • Did you solve this? – j0h Aug 7 '15 at 2:29
1

I had a similar problem with two servers. To stress the system as little as possible, I use nice and ionice

#!/bin/bash
while IFS= read ip; do 
    /usr/bin/nice -n 19 \
    /usr/bin/ionice -c 3 \
    /usr/bin/rsync --delete --delete-excluded --password-file=/home/aboettger/.rsync_pwd  -av /home/aboettger/Music rsync://$ip/media;
done < host_names

Adapted for you

#!/bin/bash
while IFS= read ip; do 
    rsync --password-file=rsync_pwd_file -avz rsync://$ip/BrandStIN /home/lanein1/BrandStIN
    rsync --password-file=rsync_pwd_file -avz rsync://$ip/MarySt /home/lanein1/MarySt
    rsync --password-file=rsync_pwd_file -avz rsync://$ip/IWM /home/lanein1/IWM
done < host_names

Content of host_names

% cat host_names
192.168.2.40
192.168.2.41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.