LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-18-2017, 03:10 PM   #1
linuxnoob45
LQ Newbie
 
Registered: Apr 2017
Posts: 2

Rep: Reputation: Disabled
scp an image to multiple Ubuntu servers at once


Hello I'm fairly new to Linux but I have a 10 Ubuntu servers that I want to push an image to. I wanted to put this image on one of the servers and have it push it to all the other ones. What would a script look like for something like that or what would be the best way to get something like this done? I figured I could just scp but it would be nice to have some kind of script that would automatically push this image to every server. I really appreciate any help thank you guys
 
Old 04-18-2017, 04:41 PM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Show what you have so far, someone will be glad to help you. Depends on how you want to do it. Very simple examples:
Code:
#! /usr/bin/env bash

#List of IP addresses
list="
192.168.0.1
192.168.0.2
192.168.0.3
"

#Loop
for i in $list; do
    scp file.jpg user@$i:/path/to/
done
Or if each machine has a different user
Code:
read -p "Enter file name for transfer" fname

scp "$fname" user1@192.168.0.1:/path/to
scp "$fname" user2@192.168.0.2:/path/to
scp "$fname" user3@192.168.0.3:/path/to
or
Code:
for i in host1 host2 host3; do
    scp file.jpg user@$i:/path/to
done
etc....
 
1 members found this post helpful.
Old 04-18-2017, 05:03 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
That's a lot of logging in.

Code:
ssh-keygen -f /path/to/file_rsa -t rsa -N '' -b 4096 -q
http://rsync.net/resources/howto/rsync.html
 
1 members found this post helpful.
Old 04-18-2017, 10:31 PM   #4
linuxnoob45
LQ Newbie
 
Registered: Apr 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
That's a lot of logging in.

Code:
ssh-keygen -f /path/to/file_rsa -t rsa -N '' -b 4096 -q
http://rsync.net/resources/howto/rsync.html
I like the rsync idea but there's 10 servers now and I'd like to be able to do it to 100 servers soon. I could probably make a script with all the IPs (all remote) and have if rsync all of them? I'm extremely new to scripting I'll have to learn some more before I could make a script like that.
 
Old 04-18-2017, 10:41 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,321
Blog Entries: 28

Rep: Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140
There is cluster ssh, which I learned about from TLLTS.

There is also cluster scp; it might be worth a look.
 
Old 04-19-2017, 04:34 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by linuxnoob45 View Post
I like the rsync idea but there's 10 servers now and I'd like to be able to do it to 100 servers soon. I could probably make a script with all the IPs (all remote) and have if rsync all of them? I'm extremely new to scripting I'll have to learn some more before I could make a script like that.
Then learn soon?
10 hosts is a great manageable start, for a guy with no skill and no script and no ssh-keys.
 
Old 04-19-2017, 07:50 AM   #7
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
If you're ever going to do more than one task/job like that then Rundeck FTW!
 
Old 04-19-2017, 11:17 AM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
rundeck is good stuff.

OP: see also https://www.linuxquestions.org/quest...4/#post5691995
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu iso image installtion on multiple computers fright Linux - General 3 05-19-2016 08:49 PM
scp the file and execute it on multiple servers AshwiniIngale Programming 2 01-15-2013 02:19 AM
Bash quesion - scp on multiple hosts to multiple directories in each one mierea.ciprian Programming 2 06-22-2012 12:27 PM
LXer: Multiple Firebird Servers on Ubuntu LXer Syndicated Linux News 0 02-23-2011 05:21 AM
Linking Multiple Ubuntu Servers bkerensa Ubuntu 3 08-22-2010 11:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration