Copy files from multiple servers to one server


Below is a script which should allow you to copy multiple files that exist on different servers to one location.

You will need SSH keys setting up if you dont want to enter in the password for each time the request is sent to the server.

Further info here

servers.txt contents

server1
server2
server3
server4
server500
#!/bin/bash -
#===============================================================================
#
#          FILE:  copyfiles.sh
#
#         USAGE:  ./copyfiles.sh
#
#   DESCRIPTION:  Copies files on multiple servers to one server from text list of servers hostnames
#
#       OPTIONS:  The right to remain silent
#  REQUIREMENTS:
#          BUGS:  
#         NOTES:  Above^
#        AUTHOR: 
#       COMPANY:
#       CREATED: 18/01/12 13:43:03 BST
#      REVISION: 
#===============================================================================
#Input
servers=$(less servers.txt)
#Action
for IP in $servers
do
scp usernamehere@$IP:/var/log/monitor/file.txt destinationserver.net:/tmp/
done
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s