Bash script to copy data on multiple servers

Script to copy data on multiple servers via shell script .In this Procedure we have 4 servers and where node 1 is the source servers and node 2 ,node 3 and node 4 are target servers.

1.Create a   file  containing all hosts.

# cat  servers
node2.mylabserver.com
node3.mylabserver.com
node4.mylabserver.com

2.Check the file which we need to copy to multiple servers.

# cat  file

This file will be copied from node1 to node 2,node3 and node4

[test@node1 ~]$

3. Script to copy the file

# for i in `cat servers`
do scp file "$i":/tmp/
done
file                                          100%   59    36.4KB/s   00:00
file                                          100%   59    40.0KB/s   00:00
file                                          100%   59    37.0KB/s   00:00

Note: servers are using password less authentication via ssh-key-gen

4. Check all servers there we will have copied data .

Leave a Reply

Your email address will not be published. Required fields are marked *