Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have more than 60 ubuntu systems in my network. I want to copy files from one system to other ubuntu systems. All IP addresses are listed in a text file.

So what command can I use to complete the task? Any bash programs?

share|improve this question
    
You sound frustrated. Please do not use that many question marks. What kind of file is it? Can't you setup a server from which the other computers download files from? –  Lekensteyn Mar 21 '11 at 19:50
add comment

3 Answers

up vote 3 down vote accepted

suppose that you have your IP addresses in a file named ips.txt, each IP in a line. create a file named, for example *scp_all.sh* and copy the following text bellow in it:

#!/bin/bash

while read LINE ; do
    scp $1 root@$LINE:$1
done < ips.txt

then execute it in this way:

./scp_all.sh /home/yaroo/Desktop/1.jpg

this is a really simple script, while it supposes that your username in all computers is root, it doesn't store password and you have to enter it each time, and it doesn't have any exception handler. if you want to change the destination address, change the second $1 in scp command with $2 and use the script in this way:

./scp_all.sh /home/yaroo/Desktop/1.jpg /home/yaroo/Downloads/just_copied.jpg

I've said that you have to enter your password for each computer, but if you have decided to use this script regularly, you can solve this problem by this simple 6-step solution described here. good luck ;-)

share|improve this answer
    
just to mention that I haven't test this script! hope for best ;-) –  sazary Mar 21 '11 at 20:24
    
Nice answer. I'll just add that I would change the first line to #! /bin/bash -e so that it will stop if any of the commands fail. –  poolie Mar 24 '11 at 10:29
    
Can you explain this line scp $1 root@$LINE:$1 ? –  karthick87 Mar 27 '11 at 6:04
    
@karthick87 yeah, we store the address of source file in a variable named $1 (we get it from command line) and the IP address of destination machine in a variable named $LINE; so we copy file $1 to machine $LINE in the same address of $1. also root@$LINE means login at machine with IP address $LINE with username root. OK? ;-) –  sazary Mar 27 '11 at 13:11
    
Yeah thankyou..But suppose if one of the system is down..Will it skip and go to the other system?? –  karthick87 Mar 27 '11 at 14:29
show 1 more comment

Lekensteyn is correct -- you should probably be pulling the files from the server, rather than pushing them to the clients from the server.

If you're going to be doing this regularly (especially with a large number of files), I would set up rsync or a version control system such as git, rather than FTP, so that the clients only have to download things that have changed.

share|improve this answer
3  
Or a configuration manager such as Puppet, bcfg2, Chef, etc. –  geekosaur Mar 21 '11 at 20:17
    
@geekosaur That comment is worthy of answerhood. I'll upvote it once you make it so. –  djeikyb Mar 22 '11 at 0:39
add comment

(upgrading from earlier comment) You may also want to look into a configuration management system such as Puppet, bcfg2, or Chef to manage distributing files across a network.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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